0

我有一个 tableView (第一个视图)和包含该表详细信息的 detailView (下一个视图)。

现在,在从第一个视图中选择特定行时,我想将所选行的索引号从第一个视图的 didSelectRowAtIndexPath 传递给下一个视图的 initWithNibName。我怎样才能做到这一点?

4

1 回答 1

1

您可以在要实例化的视图控制器中实现自己的方法并调用该方法而不是-initWithNibName:bundle:. 在该方法中,您调用

// in your view controller
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle index:(NSInteger)index {
    [self initWithNibName:nibName bundle:nibBundle];
    // do your stuff with the index here
}

// in your table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetailView *vc = [[DetailView alloc] initWithNibName:@"YourNibName" bundle:nil index:indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
    [vc release];
}
于 2011-02-10T10:40:30.253 回答