Skip to content

Commit 9f7e710

Browse files
Code cleanup and commenty things
1 parent 3da80e1 commit 9f7e710

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

DNSSwipeableCell/MasterViewController.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#import "DetailViewController.h"
1212
#import "DNSExampleImageViewCell.h"
1313

14+
static NSInteger kSelectedRowInsteadOfButton = -1;
15+
1416
@interface MasterViewController () <DNSSwipeableCellDelegate, DNSSwipeableCellDataSource>
1517

1618
@property (nonatomic, strong) NSMutableArray *cellsCurrentlyEditing;
@@ -136,7 +138,7 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
136138

137139
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
138140
{
139-
[self showDetailForIndexPath:indexPath fromDelegateButtonAtIndex:-1];
141+
[self showDetailForIndexPath:indexPath fromDelegateButtonAtIndex:kSelectedRowInsteadOfButton];
140142
}
141143

142144
#pragma mark - DNSSwipeableCellDataSource
@@ -168,7 +170,6 @@ - (NSInteger)numberOfButtonsInSwipeableCell:(DNSSwipeableCell *)cell
168170
- (NSString *)swipeableCell:(DNSSwipeableCell *)cell titleForButtonAtIndex:(NSInteger)index
169171
{
170172
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:cell.center];
171-
172173
switch (index) {
173174
case 0:
174175
return NSLocalizedString(@"Delete", @"Delete");
@@ -189,6 +190,8 @@ - (NSString *)swipeableCell:(DNSSwipeableCell *)cell titleForButtonAtIndex:(NSIn
189190
- (UIImage *)swipeableCell:(DNSSwipeableCell *)cell imageForButtonAtIndex:(NSInteger)index
190191
{
191192
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:cell.center];
193+
194+
//Return a user image for the first row only.
192195
if (indexPath.row == 0 && index == 1) {
193196
return [UIImage imageNamed:@"user"];
194197
} else {
@@ -264,7 +267,7 @@ - (void)showDetailForIndexPath:(NSIndexPath *)indexPath fromDelegateButtonAtInde
264267
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
265268
DetailViewController *detail = [storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
266269
NSString *title = self.itemTitles[indexPath.row];
267-
if (buttonIndex != -1) {
270+
if (buttonIndex != kSelectedRowInsteadOfButton) {
268271
NSString *textForCellButton = [self swipeableCell:cell titleForButtonAtIndex:buttonIndex];
269272
title = [NSString stringWithFormat:@"%@: %@", title, textForCellButton];
270273
} else {
@@ -275,7 +278,7 @@ - (void)showDetailForIndexPath:(NSIndexPath *)indexPath fromDelegateButtonAtInde
275278
NSString *imageName = self.imageNames[indexPath.row % self.imageNames.count];
276279
detail.detailImage = [UIImage imageNamed:imageName];
277280

278-
if (buttonIndex == -1) {
281+
if (buttonIndex == kSelectedRowInsteadOfButton) {
279282
detail.title = @"Selected!";
280283
[self.navigationController pushViewController:detail animated:YES];
281284
} else {

Library/DNSSwipeableCell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
@class DNSSwipeableCell;
1212

1313
#pragma mark - Data Source
14+
1415
@protocol DNSSwipeableCellDataSource <NSObject>
1516

1617
@required

Library/DNSSwipeableCell.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ - (void)updateConstraints
7777
{
7878
[super updateConstraints];
7979
if (!self.contentViewLeftConstraint) {
80+
//Pin content view to left and right of screen, grab left and right constraints.
8081
NSDictionary *views = @{ @"myContentView" : self.myContentView };
8182

8283
NSArray *verticalConstraints = [NSLayoutConstraint
@@ -175,18 +176,21 @@ - (UIButton *)buttonForIndex:(NSInteger)index previousButtonMinX:(CGFloat)previo
175176
button.tintColor = [UIColor whiteColor];
176177
}
177178

179+
//Add 8pt of padding on the left and right.
178180
[button setContentEdgeInsets:UIEdgeInsetsMake(0, 8, 0, 8)];
179181

180182
if ([self.dataSource respondsToSelector:@selector(swipeableCell:fontForButtonAtIndex:)]) {
183+
//Set font if provided.
181184
button.titleLabel.font = [self.dataSource swipeableCell:self fontForButtonAtIndex:index];
182185
}
183186

184-
//Size it to fit the contents
187+
//Size the button to fit the contents
185188
[button sizeToFit];
186189

187-
if (button.frame.size.width < 44.0f) {
190+
CGFloat appleRecommendedMinimumTouchPointWidth = 44.0f;
191+
if (button.frame.size.width < appleRecommendedMinimumTouchPointWidth) {
188192
CGRect frame = button.frame;
189-
frame.size.width = 44.0f;
193+
frame.size.width = appleRecommendedMinimumTouchPointWidth;
190194
button.frame = frame;
191195
}
192196

0 commit comments

Comments
 (0)