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

我这是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];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值