1. Introduction
頁面間的傳值,這是一個任何程式都存在的問題,也是必須解決的問題。
在使用storyboard之後,我們有兩種方式進行頁面間的傳值:
假設A、B兩個頁面,如果A跳轉到B且傳值,則可以使用Segue;
否則需要使用委托。
2. Segue的使用
在ViewController.m中加入如下代碼:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
id segue2=segue.destinationViewController;
[segue2 setValue:@"sd" forKey:@"greetingText"];
NSLog(@"點選設定");
}
在DetailController.m中加入如下代碼:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Blog.text=self.greetingText;
}
參考代碼項目位址:https://github.com/zhengjin/JzhengDemo/tree/again/Sqlite3Demo
轉載于:https://www.cnblogs.com/IT-Chris/archive/2012/09/05/2672663.html