我试图从我的一个观点中提出一个模态视图。演示者视图已显示为自定义视图中的模式。我的问题是我无法在新的Modal视图中看到“完成”按钮。以下是我的代码。我错过了什么吗?
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];
}
答案 0 :(得分:2)
如果我理解这个问题,你可以尝试这样的解决方案:
在要从实际视图中显示的模态视图控制器的viewDidLoad
或init
方法中写下此内容:
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
是指向你想要显示的视图控制器的指针/变量...我通常这样做是为了解决像你这样的问题...但是,检查代码是因为我还没有测试过它:)
希望它有所帮助!