当我在 iOS 4.3 中调用 ViewDidAppear 时,它不起作用?

Posted

技术标签:

【中文标题】当我在 iOS 4.3 中调用 ViewDidAppear 时,它不起作用?【英文标题】:ViewDidAppear doesn't work when i call it in iOS 4.3? 【发布时间】:2012-01-02 15:50:11 【问题描述】:

我有一个包含四个 UIViewController 的 UITabBarController,当我想调用 viewDidAppear 时它不起作用。我不明白为什么这仅发生在 ios 4.3 上?

//
UINavigationController *nav3 = [[UINavigationController alloc] init];
SearchViewController *searchViewController = [[SearchViewController alloc] init];
searchViewController.context = context;

[nav3 pushViewController:searchViewController animated:NO];
[arrayViewController addObject:nav3];

[nav3 release]; [searchViewController release];

//
UINavigationController *nav4 = [[UINavigationController alloc] init];
FavorisViewController *favorisViewController = [[FavorisViewController alloc] init];
favorisViewController.context = context;

[nav4 pushViewController:favorisViewController animated:NO];
[arrayViewController addObject:nav4];

[nav4 release]; [favorisViewController release];

我最喜欢的 UIViewController:

     #pragma mark - View lifecycle

     - (void)viewDidLoad
      
         [super viewDidLoad];

          NSError *error;
          NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
          fetch.entity = [NSEntityDescription entityForName:@"Businesses" inManagedObjectContext:context];
          fetchObject = [context executeFetchRequest:fetch error:&error];

         [fetch release];

        

      - (void)viewDidAppear:(BOOL)animated
       
          NSLog(@"test");
       

【问题讨论】:

【参考方案1】:

尝试改用UINavigationController 方法initWithRootViewController:。例如,

FavorisViewController *favorisViewController = [[FavorisViewController alloc] init];
favorisViewController.context = context;
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:favorisViewController];
[favorisViewController release];

还要注意,仅仅因为视图被推入堆栈,并不意味着它是可见的。在您选择具有该视图的选项卡之前,不应调用 viewDidAppear:

【讨论】:

以上是关于当我在 iOS 4.3 中调用 ViewDidAppear 时,它不起作用?的主要内容,如果未能解决你的问题,请参考以下文章

核心数据在 iOS 4.3 中不起作用

升级到 4.3 后的 ScreenshotClient 错误

ios 4.3 中的标签栏项目外观

Facebook iOS sdk xcode 4.3/storyboards

Xcode 4.5 与 iOs 6 在 iOs 4.3 中的问题

停止当我在 iOS 中调用“logInWithReadPermissions”方法时,你想打开 Facebook 提示吗