ios 頁面傳值4種方式(一) 之全局變量
ios 頁面傳值4種方式(一) 之全局變量
運用該方法1.解決了我在哈哈項目里查看詳細XIB第一行不能顯示hahaItem的問題~ 鼓掌~~~~~
通用的是用代理的方式實現頁面傳值,但是有時候利用其它方式也可以很巧妙的解決問題,頁面傳值一共有4種方式:
1、使用全局變量, SharedApplication,定義一個變量來傳遞.
2、使用文件,或者NSUserdefault來傳遞
3、通過一個單例的class來傳遞
4、通過Delegate來傳遞。
一:定義
AppDelegate.h
@property (nonatomic, retain) DetailViewController *detailViewController;@property (nonatomic, retain) NSString *text;
二:實現
AppDelegate.m
@synthesize detailViewController = _detailViewController;@synthesize text;
如果有定義對象, 別忘了實例化
self.detailViewController = [[[DetailViewControlleralloc]init]autorelease];
三: 調用
保存
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];appDelegate.text = textField.text;
使用
AppDelegate *app = [UIApplication sharedApplication].delegate;NSLog(@"%@", app.detailViewController.text);
在別的頁面中,可以直接使用引用和基本數據類型;
posted on 2013-10-05 16:28 ACM_Someone like you 閱讀(753) 評論(0) 收藏 舉報
浙公網安備 33010602011771號