简体   繁体   中英

White screen after presenting a modal view controller

I'm getting a white screen after presenting a modal view controller. This is how I do it:

SomeViewController *controller = [[[SomeViewController alloc] initWithManagedObjectContext:managedObjectContext] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
[navController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:navController animated:YES];

The navigation bar works fine, as I set it up in SomeViewController, but the view's contents are not visible, and all I see is the white background color of the root window.

The strange thing is, that this used to work, but now it doesn't for some reason. What could be the problem?

EDIT:

This is how I create SomeViewController:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self setTitle:@"Some View"];

    UIBarButtonItem *sortButton = [[[UIBarButtonItem alloc] initWithTitle:@"Sort" style:UIBarButtonItemStylePlain target:self action:@selector(sortButtonClicked:)] autorelease];
    [[self navigationItem] setRightBarButtonItems:[NSArray arrayWithObjects:sortButton, [self editButtonItem], nil] animated:YES];

    UIBarButtonItem *backButton = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(dismissModalViewControllerAnimated:)] autorelease];
    [[self navigationItem] setLeftBarButtonItem:backButton];

    // Hack to force landscape orientation
    UIViewController *controller = [[UIViewController alloc] init];
    [self presentModalViewController:controller animated:NO];
    [self dismissModalViewControllerAnimated:NO];
    [controller release];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (void) viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

白屏是由控制器的xib file不属于target (未选中其目标成员资格复选框)引起的。

Do you happen to have some other init meted also in the SomeViewController class? Please post the whole .m file. If so, you can try to delete the initWithNibName method and check if it shows the content.

EDIT: Another strange point is the initWithManagedObjectContext method you are using on the viewController instance. Can you explain it?

try

SomeViewController *controller = [[[SomeViewController alloc] init] autorelease];

it should work fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM