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

发布于 2024-12-23 16:33:12 字数 1388 浏览 1 评论 0原文

我有一个 UITabBarController,其中包括四个 UIViewController,当我想调用 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");
       }

I have a UITabBarController that include four UIViewController and when i want call viewDidAppear it doesn't work. I don't why this happens just for 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];

My Favorite 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");
       }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凤舞天涯 2024-12-30 16:33:12

尝试使用 UINavigationController 方法 initWithRootViewController: 代替。例如,

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

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

Try using the UINavigationController method initWithRootViewController: instead. For example,

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

Note as well that just because the view is pushed onto the stack, doesn't mean it's visible. Until you select the tab with that view, viewDidAppear: should not be called.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文