oc中類與類之間的信息參數傳遞總結出來有四種:java
直接的屬性傳值比較適用於,正向的A~B跳轉傳遞,若是是B~A回傳跳轉比較適用其餘傳值方式。此時若是用直接屬性傳值,屬性值可能爲空。ios
直接屬性傳值注意事項:設計模式
1.要將數據傳到哪個頁面(ViewController)就引用那個頭文件api
2.屬性(賦值)所要傳的值要寫在推出下一個窗口前面數組
傳值傳的是地址,a類的數組改變,b類的數組也要改變。。。若是不想改變就使用copy session
通知NSNotificationpost
協議Delegate動畫
單例設計模式spa
塊語法block設計
申明瞭代理,因此代理類須要實現中的方法,
self.delegate = b; [self.delegate methodA];
methodAclass B Bjava eesessionblockdelegatedelegate:
block(10,20);
Ablock:
return a+b;
}];
補充一點, 如動畫和模態視圖的回調也是用block實現的, 在api方法中定義了出現模態視圖的一系列操做,在finish時執行了block(),這個block如何執行就由調用這個方法的類去實現
iOS頁面跳轉:
第一種
[self.navigationController pushViewController:subTableViewController animated:YES];
//描述:經過 NSNavigationBar 進行跳轉
[self.navigationController popViewControllerAnimated:YES]; //描述:在子視圖返回到上級視圖
第二種
UIViewController *control = [[UIViewController alloc] init]; [self presentModalViewController:control animated:YES]; [control release]; //描述:經過事件進行跳轉 [self dismissModalViewControllerAnimated:YES]; //描述:經過事件進行返回。
第三種
[self.view.window addSubview:otherview]; [self.view removeFromSuperview]
數據傳遞:
1)採用代理模式 子viewcontroller設計 代理協議,定義協議接口,父viewcontroller 實現協議接口,實現子viewcontroller 退出時將相關數據更新到父視圖。
2)採用ios的消息機制 父viewcontroller註冊消息 子viewcontroller 發送消息,觸發父viewcontroller的消息處理。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setData:) name:kNotificationMessage object:nil];//註冊監聽,其中setData用來處理消息
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationMessage object:self userInfo:infoDict];//發送消息
3)採用database作爲數據中間的存儲媒介,子viewcontroller將狀態數據存入DB,父viewcontroller從DB獲取數據更新view。
4)採用ios的NSDefault 存儲
5)經過AppDelegate 中定義全局變量實現中間數據的存儲。
6.經過控制器屬性傳遞
.MainViewControllerSecondViewControllerSecondViewControllerfirstValue
重寫初始化方法,用於傳值- (id)initWithValue:(NSString *)value{if(self = [super initWithNibName:nil bundle:nil]){self.firstValue = value;}return self;}
將方法傳值與初始化寫到一塊兒此時已經將值存在中