ios 页面传值4种方式(一) 之全局变量
2013-10-05 16:28
369 查看
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);
在别的页面中,可以直接使用引用和基本数据类型;
运用该方法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);
在别的页面中,可以直接使用引用和基本数据类型;
相关文章推荐
- ios 页面传值4种方式(一) 之全局变量
- iOS 页面传值4种方式(一) 之全局变量
- ios 页面传值4种方式(四) 之通过delegate(代理)
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例)
- iOS页面之间传值的方式(NSUserDefault/Delegate/NSNotification/Block)
- 【转】iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)-- 不错
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例)
- iOS-关于页面跳转时全局变量赋值不到的问题
- iOS页面间传值的一些方式总结
- Axure PR 全局变量、页面传值与条件判断
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS页面间传值的方式
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)