开发者社区> 问答> 正文

XCode中用xib文件自定义的Table Cell,如何实现点击切换View Controller

利用xib文件自定义一个Table Cell,如何实现点击该Cell切换View Controller?

因为是使用xib文件自定义Table Cell,所以无法在storyboard中通过拖拽建立segue来实现View Controller的切换。

现在知道Table Cell有个方法TableView:didSelectRowAtIndexPath方法在点击cell后执行。但是不清楚如何在不使用segue的情况下具体实现一个View Controller的Push或者Modal。

展开
收起
a123456678 2016-07-27 11:04:59 2313 0
1 条回答
写回答
取消 提交回答
  • 在那个tableView的delegate里实现TableView:didSelectRowAtIndexPath, 在这个方法里可以初始化想要的push的view controller:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        NSLog(@"%@", self.data[indexPath.row]);
        // 初始化view controller, 可能需要使用到当前行的数据
        UIViewController *nextViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewControllerIdentifier"];
        // 如果是要push到navigation controller里的话
        [self.navigationController pushViewController:nextViewController animated:YES];
        // 如果是要使用modal view的话
        [self presentViewController:nextViewController animated:YES completion:^{
            // complete
        }];
    }
    2019-07-17 20:00:26
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载