0

这是我目前拥有的代码:

- (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];

}

}
4

1 回答 1

1

检查 indexPath.row == 是否到您想要的行。如果您的表格是静态的,您只能在情节提要中执行此操作。

于 2012-01-09T13:46:25.140 回答