以下是我目前的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath {
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"];
[self.navigationController pushViewController:detail animated:YES];
detail.rowNum.text = [NSString stringWithFormat:@"Image %d", (indexPath.row + 1)];
}
为我的表视图中的每个单元格加载相同的视图控制器。我如何声明我只希望在选择一个特定行时发生这种情况?所以例如我会将上面的内容仅适用于每一行的另一个实例的第一行?或者,这可以在Xcode的故事板部分完成吗?
更新:在回答之后我已将代码更新为此工作正常,所以我想如果没有别的话就可以使用它?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath {
if (indexPath.row == 0) {
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"];
[self.navigationController pushViewController:detail animated:YES];
detail.rowNum.text = [NSString stringWithFormat:@"Image %d", (indexPath.row + 1)];
}
if (indexPath.row == 1) {
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Forum"];
[self.navigationController pushViewController:detail animated:YES];
}
}
答案 0 :(得分:1)
检查indexPath.row ==是否为您想要的行。如果你的桌子是静态的,你只能在故事板中这样做。