如何在单击Table View Cell时打开新视图?(How to open a new view on click of Table View Cell?)

我正在开发一个具有TableView的iOS应用程序,我想做的是当点击TableView的一个单元格时,会打开一个新视图(然后它可以返回到表视图。)我尝试了一些像工作一样的东西使用segues和新的视图控制器,但它不起作用。

I am developing an iOS app which has a TableView, and I want to do sth that when a cell of the TableView is tapped, a new view opens (and then it can get back to the Table View.) I tried some things like working with segues and new view controllers, but it didn't work.

最满意答案

实现UITableViewDelegate协议,并实现该方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

在该方法中,您可以创建新视图。

Implement the UITableViewDelegate protocol, and implement the method

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Inside that method you can create your new view.

更多推荐