2013-03-26 4 views
0
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
    [[NSNotificationCenter defaultCenter] postNotificationName:ListOrMapAddReloadButton object:self]; //Add nearby buttons 
} 

В одном UIViewController здесь последовательностьПочему иногда viewDidLoad вызывается первым, а иногда называется последним?

  1. viewDidload дозвонились
  2. [[NSNotificationCenter defaultCenter] postNotificationName:ListOrMapAddReloadButton object:self];

И потому, что уведомление настроить вызывается в viewDidLoad, я как бы нужно viewDidLoad называться прежде чем «

  1. -(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

`

Как я могу добиться этого?

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(addReloadButton) name:ListOrMapAddReloadButton object:nil]; 
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(addNearbyButton) name:ListOrMapAddNearbyButton object:nil]; 

ответ

2

Положите уведомления в ViewWillAppear()

+0

Я хочу, чтобы назвать только один раз, а затем удаляются при dealloc. Поэтому я положил его на viewdidload. Я считаю, что viewdidload является подходящей «парой» для dealloc. –

+2

На самом деле самой подходящей «парой» для 'dealloc' будет' init' ... – fumoboy007

Смежные вопросы