个人觉得用这个东西在不同的viewcontroller间传东西很方便的

发消息

  [[NSNotificationCenter defaultCenter] postNotificationName:@"popView"/*消息名字,在添加监听时会用到*/       object:@"ShowHomeLineViewController"/*传的参数,多个参数就可以用数组啦*/];

收消息

1、添加监听:

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Show:)/*收到消息后的响应函数*/ name:@"popView"/*消息名字,在发消息时  指定的*/ object:nil];

2、消息处理(实现前面的Show:函数)

-(void)Show:(NSNotification*)notification

{
    NSString* str = (NSString*)[notification object];//这里取出刚刚从过来的字符串
}
3、不要忘记移除监听

[[NSNotificationCenter defaultCenter] removeObserver:self name:@"popView" object:nil];

相关文章:

  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
  • 2021-06-14
  • 2021-09-11
  • 2021-09-20
相关资源
相似解决方案