使用segue编程构造的tableview单元格

时间:2012-04-21 00:45:55

标签: ios ios5 uitableview uistoryboard uistoryboardsegue

我在界面构建器的故事板模式中避免使用静态原型单元。但是,当按下那些单元格以显示详细视图控制器时,我仍然想要使用segues。

我试图在IB中创建一个segue但它不会让我(从tableview本身拖动)所以我继续尝试编程如下:

[[UIStoryboardSegue alloc] initWithIdentifier:@"FriendProfileSegue" source:self destination:[[BBFOtherProfileController alloc] init]];

但是我仍然遇到崩溃,因为目标视图控制器没有实现segue。有什么办法绕过这个问题?如果可能的话,我更愿意在IB中创建segue。

1 个答案:

答案 0 :(得分:2)

您应该能够轻松地在IB中创建一个segue:按住Control并单击表格视图单元格,然后拖动到目标视图控制器。确保您实际上是单击表格视图单元格而不是其中的子视图。为确保这一点,您可以先在左侧面板中选择表视图单元格,然后在图表视图中按住Control键并单击并拖动它。

通常情况下,如果你没有使用IB来创建你的segues,你只需按常规方式做事:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
    // ...
    // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
}
相关问题