我们在使用Segue进行跳转的时候,往往需要传递一些数据,我们在下面的方法中进行数据传递的准备工作:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
此方法包含两个参数:
- segue:跳转的Segue,其中包含跳转的源Controller和目标Controller,我们可以获取到这两个controller的对象,并进行进一步操作。
- sender:触发这个Segue的对象。
下面进行实例演示:
1. 创建一个Single View Application,在storyboard中添加一个View Controller,然后创建一个类,命名为SecondViewController,将这个类与新添加的View Controller关联起来。
2. 在第一个ViewController页面上添加一个button,并为此button添加一个segue,指向第二个ViewController。将这个Segue的identifier设置为”passdatasegue”。
3. 在SecondViewController的页面上添加一个label,并为其创建一个IBOutlet,名字为sec