我看到一個類似的問題在這裏被問到:How to add a right button to a UINavigationController?(其他),但它不是我想要做的,而且他們不解決我的問題。向UINavigationController添加一個正確的「完成」按鈕(UIBarButtonItem)
本質上,我創建了一個名爲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];
}
不幸的是,「完成」按鈕沒有顯示..任何想法,即時通訊出錯?
嗯..同樣的事情。我認爲我錯過了一些更大的東西。我正在瀏覽http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/NavigationControllers/NavigationControllers.html,但我沒有看到我的解決方案。 – JMattos 2011-04-20 03:10:21