呈现模态视图控制器后的白色屏幕

时间:2012-04-02 06:42:36

标签: objective-c ios uiviewcontroller uinavigationcontroller

在呈现模态视图控制器后,我得到一个白色屏幕。我就是这样做的:

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

导航栏工作正常,因为我在SomeViewController中设置它,但视图的内容不可见,我看到的只是根窗口的白色背景颜色。

奇怪的是,这曾经起作用,但现在却不是出于某种原因。 可能是什么问题?

修改

这就是我创建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);
}

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

您是否碰巧在SomeViewController类中还有其他一些初始化?请发布整个.m文件。如果是这样,您可以尝试删除initWithNibName方法并检查它是否显示内容。

编辑: 另一个奇怪的点是您在viewController实例上使用的initWithManagedObjectContext方法。你能解释一下吗?

答案 2 :(得分:-1)

尝试

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

它应该可以正常工作。