开发者

How to pass the number of row selected from didSelectRowAtIndexPath to initWithNibName?

I have a tableView (first view) and the detailView (next view) containing the details of that table.

Now on selecting a particular row from the first view I want to pass the index number of the selected row from didSelectRowAtIndexPath of the first view to the 开发者_JAVA百科initWithNibName of the next view. How can I do that?


You can implement an own method in your view controller you want to instantiate and call that method instead of -initWithNibName:bundle:. In that method, you call

// 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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜