标签:
介绍一种在storyboard上拖控件创建segue的方法。
// 首先去翻译了下Segue
// 来源:https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/UsingSegues.html
// 定义:Segue表示storyboard文件中两个ViewController之间的转换(?)。通常由A视图控制器的按钮、表格行或手势指向B视图控制器。
// 触发:由UIKit实现,可使用notifications在A、B间传输数据。segue被触发后工作流程如下
提供shouldPerformSegueWithIdentifier:sender:方法中止跳转所需的步骤,如不新建segue和B;
提供prepareForSegue:sender:方法传输数据。
// 类型:原表如下,几个segue的区别是:show是把B堆在A上,detail用B替换A,Modally用模版显示B,Popover用B作弹窗。
Segue type |
Behavior |
---|---|
Show (Push) |
This segue displays the new content using the UIKit uses the |
Show Detail (Replace) |
This segue displays the new content using the UIKit uses the |
Present Modally |
This segue displays the view controller modally using the specified presentation and transition styles. The view controller that defines the appropriate presentation context handles the actual presentation. |
Present as Popover |
In a horizontally regular environment, the view controller appears in a popover. In a horizontally compact environment, the view controller is displayed using a full-screen modal presentation. |
// 步骤
1. 选中cell,关联cell与B,segue类型选择selection show (detail)
2. 在A对应的Controller中覆盖prepareForSegue方法
class AController: UIViewController, UITableViewDataSource,UITableViewDelegate {
// ...
// 目前只有一个segue,所以没有判断viewControllerId,产生错误再学怎么区分
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let index : Int = (self.table.indexPathForSelectedRow?.row)!
let data:VideoSummary = videoSummaries[index]
let view : BController = segue.destinationViewController as! VideoViewController
view.selectedVideo = data
}
}
3. 在B对应的Controller中添加selectedVideo属性
class BController: UIViewController , UITableViewDataSource,UITableViewDelegate {
var selectedVideo : VideoSummary! // 注意感叹号
//...
}
// 成功。
标签:
原文地址:http://www.cnblogs.com/yinkw/p/5589008.html