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

ios 监听(NSNotification)的使用(在项目中已使用) .

2013-07-12 16:58 459 查看
我这是ipad开发,在首次进入系统后,点击左边视图的添加按钮,然后presentModalViewController添加登陆用户的视图。

在视图保存数据是然后请求监听触发事件,在leftViewController页面进行请求的接受

1.注册监听器

-(void)goChange:(NSNotification *)notification
{
    //拿到通知内容。
    NSDictionary *dic = [notification
userInfo];
    ZYRootViewController *rootView=[[ZYRootViewController
alloc] init];
    rootView.userListArray=[dic
objectForKey:@"myTable"];
    [rootView.myTableView
reloadData];
}
2.在loadview方法注册监听者

//注册监听者。
    [[NSNotificationCenter
defaultCenter]addObserver:self
selector:@selector(goChange:)
name:@"myTableView"
object:nil]; 
//收到通知后,执行方法:goChange:,object:nil表示所有的用户
3.点击保存按钮的请求触发事件(执行监听者选择器的方法)
    User *user=[[User
alloc] init];
    ZYRootViewController *rootView=[[ZYRootViewController
alloc] init];
    rootView.userListArray=[user
getUser];
    [rootView.myTableView
reloadData];
    [user release];
    [rootView release];
     NSDictionary *dic = [NSDictionary
dictionaryWithObject:rootView.userListArray
forKey:@"myTable"];
    [[NSNotificationCenter
defaultCenter]postNotificationName:@"myTableView"
object:self
userInfo:dic];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: