两 个页面切换我会,并且这个很简单了。。
但发现不能传值,为什么?
谢谢啦~
1,在init函数中可以加个参数。Initwithxxxx
2,委托3,通知
4,单例
代理 属性 单列 通知 传值都行的啊
对于不同的viewcontroller之间数据的共享和处理,我总结有下面几种方式
1)采用代理模式 子viewcontroller设计 代理协议,定义协议接口,父viewcontroller 实现协议接口,实现子viewcontroller 退出时将相关数据更新到父视图。
2)采用ios的消息机制 父viewcontroller注册消息 子viewcontroller 发送消息,触发父viewcontroller的消息处理。
3)采用database做为数据中间的存储媒介,子viewcontroller将状态数据存入DB,父viewcontroller从DB获取数据更新view。
4)采用ios的NSDefault 存储
5)通过AppDelegate 中定义全局变量实现中间数据的存储。
其实就分为两大类:直接传递与间接传递。其中间接传递里面还可以定义一个singleton,用来共享数据。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
FirstViewController *firstVC = [[FirstViewController alloc] init];
[self.navigationController pushViewController:firstVC animated:YES];
[firstVC release];
firstVC.label.text = [data objectAtIndex:indexPath.row];
}
在first.h
@interface first : UIViewController {
NSArray * array_;
}
@property (nonatomic, retain) NSArray * array_;
@end
在first.m
@implementation first
@synthesize array_;
- (void)displayNextViewController {
second * sc = [[second alloc] init];
sc.array_ = self.array_;//把自己的array传给second类得array
[self presentModalViewController:sc animated:YES];
}
在second.h中
@interface second : UIViewController {
NSArray * array_;
}
@property (nonatomic, retain) NSArray * array_;
@end
这个@property就是设置属性。