首页 > 代码库 > 点击TableView中某行进入下一级界面
点击TableView中某行进入下一级界面
TableView这个控件在iOS的开发中非常的常见,他可以较好的展示一个层级结构。这里主要介绍,在点击某个条目的时候,如何进行跳转的下一个界面。以下是官方的关于这个跳转如何去实现,和如何去传递数据的过程。
Storyboards make it easy to pass data from one scene to another via the prepareForSegue:sender: method of the UIViewController class. This method is called when the first scene (the source) is about to transition to the next scene (the destination). The source view controller can implement prepareForSegue:sender: to perform setup tasks, such as passing information to the destination view controller about what it should display in its table view. Listing 3-1 shows one implementation of this method.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{if ([[segue identifier] isEqualToString:@"ShowDetails"]) { MyDetailViewController *detailViewController = [segue destinationViewController]; NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; detailViewController.data = [self.dataControllerobjectInListAtIndex:indexPath.row];} }
A segue represents a one-way transition from a source scene to a destination scene. One of the consequences of this design is that you can use a segue to pass data to a destination, but you can’t use a segue to send data from a destination to its source. To solve this problem, you create a delegate protocol that declares methods that the destination view controller calls when it needs to pass back some data.
点击TableView中某行进入下一级界面
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。