我正在執行inline date picker in a table view。但是,我正在努力解決'didSelectRowAtIndexPath'問題。'didSelectRowAtIndexPath'檢測到太多的行
的部分和的tableView的行被定義使用NS_ENUM,如下所示:
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
};
然後,我實現「didSelectRowAtIndexPath方法」,這樣,如果「ThirdSectionFirstRow」由用戶選擇,日期選擇器將被顯示。我使用NSLog來幫助我調試。
- (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];
}
但是,根據我的記錄結果時,我依次選擇每行,似乎這種方法被稱爲不只有「ThirdSectionFirstRow」被選擇,而且如果「FirstSectionFirstRow」和「SecondSectionFirstRow」。任何人都可以幫助我發現我的邏輯中的缺陷,以便僅在選擇「ThirdSectionFirstRow」時調用此方法?謝謝!
真的嗎?爲什麼downvote? – narner 2015-02-06 20:50:36
所有枚舉都從零開始,所以它們全部重疊 - 它們只是整數,並且在執行時這些名稱早已消失。但是無論如何你無法按行號唯一標識一個單元格。 – 2015-02-06 20:50:40
我認爲你應該重新考慮你的整個方法。使用這組枚舉來定義段和行不是處理分段表視圖的常用方法。 – rdelmar 2015-02-06 20:50:56