Objective c 为什么有时首先调用viewDidLoad,有时调用它';什么叫后者?
在一个Objective c 为什么有时首先调用viewDidLoad,有时调用它';什么叫后者?,objective-c,uiviewcontroller,viewdidload,Objective C,Uiviewcontroller,Viewdidload,在一个UIViewController中,序列如下 viewDidloadget called [[NSNotificationCenter defaultCenter]postNotificationName:ListOrmPaddReloadButton对象:self] 因为通知设置是在viewDidLoad中调用的,所以我需要先调用viewDidLoad` -(void)tabBarController:(UITabBarController*)tabBarController didSe
UIViewController
中,序列如下
viewDidload
get called[[NSNotificationCenter defaultCenter]postNotificationName:ListOrmPaddReloadButton对象:self]代码>
-(void)tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController*)viewController
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
[[NSNotificationCenter defaultCenter] postNotificationName:ListOrMapAddReloadButton object:self]; //Add nearby buttons
}
将您的通知放入viewwillbeen()我希望它只被调用一次,然后在dealloc中删除。因此,我把它装上了。我认为viewdidload是一个适合dealloc的“对”。实际上,
dealloc
最合适的“对”应该是init
…
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(addReloadButton) name:ListOrMapAddReloadButton object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(addNearbyButton) name:ListOrMapAddNearbyButton object:nil];