添加正确的“完成”按钮 (UIBarButtonItem) 到 UINavigationController
我看到这里提出了类似的问题: 如何添加UINavigationController 的右键?(以及其他)但这并不完全是我想要做的,而且他们没有解决我的问题。
本质上,我创建了一个名为 WebViewViewController 的 UIViewController,其上有一个 UIWebView,它将使用presentModalViewController 显示。本质上它是一个迷你网络浏览器,用于显示网页,同时让用户保持在应用程序中,而不是启动 Safari。
viewController 执行以下操作以使其显示...并且“完成”按钮旨在提供关闭浏览器的位置。
-(IBAction)visitFacebook {
WebViewViewController *rootController = [[WebViewViewController alloc] init];
rootController.webURL = @"http://www.facebook.com/";
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(done:)];
[navigationController.navigationItem setRightBarButtonItem:doneButton animated:YES];
[navigationController.navigationItem setTitle:@"Facebook"];
if (rootController) {
[self presentModalViewController:navigationController animated:YES];
}
[doneButton release];
[rootController release];
}
不幸的是,“完成”按钮没有显示……有什么想法我哪里出错了吗?
I see that a similar question was asked here: How to add a right button to a UINavigationController? (among others) but its not quite what I'm looking to do and they arent solving my problem.
Essentially, I've created a UIViewController called WebViewViewController with a UIWebView on it which will be shown using presentModalViewController. Essentially its a mini web browser to display a web page while keeping the user in the app rather than launching Safari.
The viewController does the following to get it to show... and the "done" button is meant to provide a place to close the browser.
-(IBAction)visitFacebook {
WebViewViewController *rootController = [[WebViewViewController alloc] init];
rootController.webURL = @"http://www.facebook.com/";
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(done:)];
[navigationController.navigationItem setRightBarButtonItem:doneButton animated:YES];
[navigationController.navigationItem setTitle:@"Facebook"];
if (rootController) {
[self presentModalViewController:navigationController animated:YES];
}
[doneButton release];
[rootController release];
}
Unfortunately the "done" button isnt showing.. any ideas where im going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试以下
Try with below
也许您正在寻找更像这样的东西:
Perhaps you're looking for something more like this:
只是这一行代码为我显示了完成按钮。
Just this one line code displayed done button for me.