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);
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值