0

我有一个包含四个 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");
       }
4

1 回答 1

0

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

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

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

于 2012-01-02T15:54:21.583 回答