【发布时间】:2017-01-03 23:24:21
【问题描述】:
我想知道在NSNotificationCenter defaultCenter中调用viewWillAppear:方法好不好。
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(viewWillAppear:) name:UIApplicationDidBecomeActiveNotification object:nil];
或者
-(void)setUpInitialization{
// dump code here in ViewWillAppears.
}
调用setUpInitialization方法
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(setUpInitialization) name:UIApplicationDidBecomeActiveNotification object:nil];
如果直接调用viewWillAppear是不是很好的实现方式?
【问题讨论】:
-
当应用激活时,
viewWillAppear:不是已经被系统调用了吗? -
@mattsson 是的,应用程序已为 tabbarcontroller 激活。
-
那为什么要使用通知再次调用它呢?
-
我不建议直接调用
viewWillAppear- 首先它会破坏视图生命周期层次结构调用,其次如果有人从你的类中子类他可能很难调试他自己的类,因为viewWillAppear将比平时更频繁地打电话。
标签: objective-c nsnotificationcenter