I'm working on implementing an inline date picker in a table view. However, I'm struggling on a problem with 'didSelectRowAtIndexPath'.
The sections and rows of the tableView are defined using NS_ENUM, as shown below:
typedef NS_ENUM(NSInteger, SectionOne)
{
SectionOneFirstRow = 0,
SectionOneSecondRow,
TotalSectionOneRows
};
typedef NS_ENUM(NSInteger, SectionTwo) {
SectionTwoFirstRow = 0,
SectionTwoSecondRow,
SectionTwoThirdRow,
SectionTwoFourthRow,
TotalSectionTwoRows
};
typedef NS_ENUM(NSInteger, ThirdSection) {
ThirdSectionFirstRow = 0,
TotalThirdSectionRows
};
typedef NS_ENUM(NSInteger, Section) {
SectionOne = 0,
SectionTwo,
SectionThree,
TotalSections,
TotalComponents,
TotalRows
};
Then, I implement 'didSelectRowAtIndexPath' so that if 'ThirdSectionFirstRow' is selected by the user, a date picker will be displayed. I'm using NSLog to help me debug.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == ThirdSectionFirstRow && self.datePickerIsShowing == NO){
NSLog(@"Row selected");
[self showDatePickerCell];
} else{
[self hideDatePickerCell];
}
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
However, based on my logging results when I select each row in turn, it seems that this method is called not only if 'ThirdSectionFirstRow' is selected, but also if 'FirstSectionFirstRow' and 'SecondSectionFirstRow'. Can anyone help me spot the flaw in my logic so that this method is called only if 'ThirdSectionFirstRow' is selected? Thank you!