“完成”按钮在“模态”视图中不可见

时间:2012-06-22 21:07:37

标签: iphone objective-c cocoa-touch uiviewcontroller modalviewcontroller

我试图从我的一个观点中提出一个模态视图。演示者视图已显示为自定义视图中的模式。我的问题是我无法在新的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];
}

enter image description here

1 个答案:

答案 0 :(得分:2)

如果我理解这个问题,你可以尝试这样的解决方案:
在要从实际视图中显示的模态视图控制器的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是指向你想要显示的视图控制器的指针/变量...我通常这样做是为了解决像你这样的问题...但是,检查代码是因为我还没有测试过它:) 希望它有所帮助!