1

我试图从我的一个视图中呈现一个模态视图。演示者视图已从自定义视图显示为模式。我的问题是我无法在新的模态视图中看到“完成”按钮。下面是我的代码。我错过了什么吗?

    UIViewController *aViewController = [[UIViewController alloc] init];
    UINavigationController *aNavigationController = [[[UINavigationController alloc] initWithRootViewController:aViewController] autorelease];
    [aNavigationController.navigationBar setBarStyle:UIBarStyleBlack];
    UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissMe)];
    [aNavigationController.navigationItem  setLeftBarButtonItem:aBarButtonItem];
    MyView *aView = [[MyView alloc] initWithFrame:self.view.frame];
    [aViewController.view addSubview:aView];
    [self presentModalViewController:aNavigationController animated:YES];
    [aViewController release];

- (void)dismissMe {
    [self dismissModalViewControllerAnimated:YES];
}

在此处输入图像描述

4

1 回答 1

3

如果我理解这个问题,你可以尝试这样的解决方案:在你想从实际视图中显示的模态视图控制器的or方法中
写下这个:viewDidLoadinit

UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self selector:@selector(dismissMe)];
self.navigationController.leftBarButtonItem = done;

并实现你dismissMe的方法。
取而代之的是,在演示者控制器中写下您想要呈现新模态控制器的位置:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controllerYouWantToShow];
[self presentModalViewController:navController animated:YES];

显然,controllerYouWantToShow是指向您要显示的视图控制器的指针/变量...我通常这样做是为了解决像您这样的问题...但是,请检查代码,因为我尚未对其进行测试:)
希望对您有所帮助!

于 2012-06-22T22:17:01.057 回答