在storyboard中实现tableView didSelectRowAtIndexPath

时间:2014-02-13 16:00:50

标签: ios user-interface storyboard

如何在storyboard中实现tableView didSelectRowAtIndexPath。我已经创建了一个创建表的视图控制器。我不知道在故事板中该怎么做才能在点击表格中的每个单元格时转换视图。

这是我最初在该方法中以编程方式进行的操作:

Show *show = [self.shows objectAtIndex:indexPath.section];
ShowContentItem *showItem = show.showContentItems[indexPath.row];

if ([showItem.contentType isEqualToString:@"Headline_Section"]) {
    HeadlinesViewController *headlinesVC = [[HeadlinesViewController alloc] init];
    headlinesVC.shows = [[NSMutableArray alloc] initWithObjects:show, nil];
    [self.navigationController pushViewController:headlinesVC animated:YES];
} else {
    NSInteger contentIndex = [self.storyPostContent indexOfObject:showItem];
    NSRange rangeForView = NSMakeRange(contentIndex, [self.storyPostContent count] - contentIndex );

    ShowContentViewController *showContentVC = [[ShowContentViewController alloc] init];
    showContentVC.contentList = [self.storyPostContent subarrayWithRange: rangeForView];

    [self.navigationController pushViewController: showContentVC animated:YES];
}

我如何具体改变上面的代码以使用故事板?

1 个答案:

答案 0 :(得分:1)

您可以控制从原型单元格到目标控制器的拖动。然后在prepareForSegue中你做这样的事情:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"yourSegue"]) {
        yourViewController *destinationController = segue.destinationViewController;
        destinationController.someVariable = yourTable.indexPathForSelectedRow;
    }

}