为什么有时会首先调用viewDidLoad,有时它被称为后者?

时间:2013-03-26 04:46:15

标签: objective-c uiviewcontroller viewdidload

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

在一个UIViewController中,这里是序列

  1. viewDidload被召唤
  2. [[NSNotificationCenter defaultCenter] postNotificationName:ListOrMapAddReloadButton object:self];
  3. 因为在viewDidLoad中调用了通知设置,所以我需要在`

    之前先调用viewDidLoad
    1. -(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    2. `

      我怎么能实现这个目标?

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

1 个答案:

答案 0 :(得分:2)

将您的通知放在ViewWillAppear()