在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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. (Objective-C) func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { if(segue.identifier == "ShowDetails"){ var detailViewController:MyDetailViewController ! = segue.destinationViewController as MyDetailViewController var index = tableView.indexPathForSelectedRow() detailViewController.data = dataController[index!.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. 以上的过程是在tableViewCell与DetailView界面建立Segue连接的情况下,并且设置了Segue的identifer。 Segue是完全在Storyboard可以拖拽建立,比较简单,关于如何建立Segue请网上查找下资料。
|
请发表评论