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 {
0 commit comments