2013-03-26 72 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的「pair」。 – 2013-03-26 04:55:55

+2

其實'dealloc'最適合的「pair」是'init' ... – fumoboy007 2013-03-26 05:30:21