iOS storyBoard中tableViewCell传值方法

一般在storyboard中传值通过identifier的值来控制segue的跳转和传值,但是,如果在tableView中,由于cell特别多,不可能创建n个identifier标识符,这里通过NSIndexPath *indexPath = [_tableView indexPathForSelectedRow];的方法来获取当前选中的cell,这样拿到IndexPath就可以拿到model了并进行传值了

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    //获取当前点击的cell的IndexPath
    NSIndexPath *indexPath = [_tableView indexPathForSelectedRow];
    TYItemModel *model = self.dataArr[indexPath.row];
    TYLiveViewController *liveVC = (TYLiveViewController *)segue.destinationViewController;
    liveVC.model = model;
    NSLog(@"%@",indexPath);
}

posted @ 2017-04-10 15:58  qqcc1388  阅读(898)  评论(0编辑  收藏  举报