开发者

Problem Loading View Controller in Core Data Project

I have just recently begun to learn to use core data in XCode 4, and I'm having a very odd problem loading my first view controller from the app delegate in core data projects. I'm really not sure what I'm doing wrong, only that what I'm doing works very well when core data is not implemented, but does not when it is.

What I find happening is that the appDelegate will load and then it will begin to load the view controller (I can get it to log that it went through the initWithNibName method). But then the view controller disappears and all I see is the main window. There are no errors generated in the error log.

Here is the relevant code from the appDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // other code here

    UINavigationController *navigationController = [[[UINavigationController alloc]  init] autorelease];

    HomeViewController *viewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
    viewController.title = @"My Company";
    [navigationController pushViewController:viewController animated:NO];

    [window addSubview:navigationController.view];

    [viewController release];

    [self.window makeKeyAndVisible];
    return YES;
}

The view controller basically only has stub data in it at the moment, but I can post any of the methods upon request. Thank you in advance for your help.

UPDATE: Well, I finally got this to work on my own, though I'm not sure why it worked. All I did was remove the navigation controller as a property of the app delegate and alloc init autoreleased it in the didFinishLaunchingWithOptions method. After that it worked fine. The code posted above is what finally worked. Oddly enough, though, I tried the same thing in another project I am working on and it didn't work on that one.

Here is the code from the second project

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UINavigationController *navigationController = [[[UINavigationController alloc]  init] autorelease];
    StartViewController *viewController = [[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil];

    [navigationController setNavigationBarHidden:YES];
    [navigationController pushViewController:viewController animated:NO];

    [window addSubview:navigationController开发者_运维技巧.view];
    [viewController release];

    [self.window makeKeyAndVisible];
    return YES;
}


Try something different like this:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  HomeViewController *viewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
  viewController.title = "My Company";
  [navigationController pushViewController:viewController animated:NO];

  [viewController release];

  [window addSubview:navigationController.view];
  [self.window makeKeyAndVisible];
  return YES;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜