我有一个 UITableView,我已经分配了部分。将 didSelectRowAtIndex 与 indexPath.row 一起使用时,我没有得到正确的值。假设我在第 2 部分,然后它再次从 0 开始行索引,因此我得到了错误的索引。
谁能告诉我如何解决这个问题?我意识到可以通过 indexPath.section 获取部分索引,但我不知道如何使用它。
bandDetailViewController.band = [self.programArray objectAtIndex:indexPath.row];
我希望你能帮助我。提前致谢:-)
编辑:
示例数据。我的表格 View 单元格是从此 plist 加载的。
<array>
<dict>
<key>name</key>
<string>Alphabeat</string>
<key>description</key>
<string>Long description.</string>
<key>scene</key>
<string>Store Scene</string>
<key>date</key>
<date>2011-02-04T20:09:40Z</date>
<key>hasDate</key>
<true/>
<key>weekDay</key>
<string>Onsdag</string>
<key>youtubeVideo</key>
<string>http://www.youtube.com/watch?v=dB01PTZNpBc</string>
</dict>
<dict>
<key>name</key>
<string>Anne Linnet</string>
<key>description</key>
<string>Long description.</string>
<key>scene</key>
<string>Store Scene</string>
<key>date</key>
<date>2011-02-04T20:09:40Z</date>
<key>hasDate</key>
<true/>
<key>weekDay</key>
<string>Onsdag</string>
<key>youtubeVideo</key>
<string>http://www.youtube.com/watch?v=jWMSqS7fL9k</string>
</dict>
</array>
最佳答案
我也遇到了这个问题。我找到了一个使用您提到的部分编号的简单解决方案以下代码使用 segues 从具有两个不同行的两个不同部分导航到新的 controlView。非常简单的解决方案!
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0)
{
switch(indexPath.row) {
case 0:
[self performSegueWithIdentifier:@"Mission" sender:self];
break;
case 1:
//[self performSegueWithIdentifier:@"Music" sender:self];
break;
}
}else{
switch(indexPath.row) {
case 0:
[self performSegueWithIdentifier:@"Contact" sender:self];
break;
case 1:
//[self performSegueWithIdentifier:@"Home" sender:self];
break;
}
}
}
关于iphone - didSelectRowAtIndexPath 与部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4923572/