您的位置:首页 > 移动开发 > IOS开发

ios页面传值的几种方法

2014-12-19 09:58 267 查看
1.属性
2.方法
3.代理方法
4.SharedApplication
5.NSUserdefault
6.通过一个单例的class来传递

属性这种方法传值挺方便的,只需要拿到它的指针,如果重新声明一个指针,就不是原来的内容,不是同一个指针,因此需要传指针。

xxxViewController *document = [[xxxViewController alloc] initWithStyle:UITableViewStyleGrouped];
document.docDict = [self.dataArray objectAtIndex:indexPath.row];
document.properties = 要传的值
[self.navigationController pushViewController:document animated:YES];
[document release];


方法传值这个只要声明要传到那个类的实例变量和方法,就把当前的页面的值传过去。

代理适合从后向前传值。详细参考。

NSUserdefault这个是一个字典,经常用来存储用户名和密码。但是传多次时候有可能覆盖前面的内容。

SharedApplication相当与一个全局变量 [UIApplication UISharedApplication].delegete这个方法还没用过

单例这个也相当与全局的变量

[[UIApplication sharedApplication] delegate];
你可以在AppDelegate里写一个宏:

#define APP_DELEGATE        ((AppDelegate *)[[UIApplication sharedApplication] delegate])


后面就能用

#import "AppDelegate.h"
[APP_DELEGATE.window addSubview:xxxxxx];

FmovieAppDelegate* appDelegate = (FmovieAppDelegate*)[[UIApplication sharedApplication] delegate];

[self.navigationController pushViewController:appDelegate.cinemaViewController animated:YES];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: