通過webview,可以設置一個簡單的「返回」按鈕(無論是在導航欄還是頂部工具欄中),該按鈕不會在WebView的第一個URL上顯示後退按鈕,而且只能出現在第二個URL上以回到第一個?導航WebView
除非出現這種錯誤,否則在很多混合原生/網絡應用程序(如News應用程序)中,您經常會在表格中看到新聞文章(HTML頁面而非「xcode」中的表格)到文章詳細頁面(再次,HTML而不是本地編碼) - 我無法確定的是,詳細信息頁面(webview中的第2個URL)是如何顯示的「後退按鈕」,但表格(webview中的第1個URL)沒有按鈕顯示在這些類型的應用程序?
目前,我有一個webview的描述,在屏幕頂部的工具欄中有一個'後退'欄按鈕項目(出口作爲'cangoback'爲WebView),但按鈕是從一開始就可見的,當沒有以「回去」頁面 -
我已經有了簡單地說就是:
網頁視圖 - 第一URL,HTML表格 - 「返回」按鈕顯示,但不活躍
(當然)Webview - 第二個URL,HTML詳細信息頁面 - '返回'按鈕顯示,並可以返回。
如何讓它只出現在第二個網址上,或者在第一個網址上被隱藏?
問候 蘭迪
EDIT(11月25日)
這裏是我的H:
#import <UIKit/UIKit.h>
#import "FilmnoirNavController.h"
@interface FilmnoirViewController : UIViewController <UIWebViewDelegate> {
IBOutlet UIWebView *webView;
IBOutlet UIBarButtonItem *backButton;
}
@property (nonatomic, retain) UIWebView *webView;
@property (nonatomic, retain) UIBarButtonItem *backButton;
- (IBAction)backButtonClicked:(id)sender;
@end
,這裏是我的L:
#import "FilmnoirViewController.h"
@implementation FilmnoirViewController
@synthesize webView;
@synthesize backButton;
- (IBAction)backButtonClicked:(id)sender {
[webView goBack];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Initialization code
}
return self;
}
/*
Implement loadView if you want to create a view hierarchy programmatically
- (void)loadView {
}
*/
/*
If you need to do additional setup after loading the view, override viewDidLoad. */
- (void)viewDidLoad {
NSString *urlAddress = @"http://www.filmsite.org/filmnoir.html";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
}
- (void)webViewDidFinishLoad {
// Other stuff if necessary...
// Could use hidden instead of enabled if you don't even want
// the button to be visible
backButton.enabled = (webView.canGoBack);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[webView release];
[super dealloc];
}
@end
我的IB佈局:
Filmnoir View Controller (Film noir)
> View
>>Web View
>>Tool Bar
>>>Bar Button Item (Back)
以爲我像這樣的東西隱藏後退按鈕了吧:
- (void)webViewDidFinishLoad {
BOOL ableToGoBack = [webView canGoBack];
if (ableToGoBack == NO) {
[backButton setHidden:YES];
}
else {
[backButton setHidden:NO];
}
,但警告說,一個UIbarButton項目可能不setHidden迴應 - 而事實上並非如此。
感謝Sbrocket,但我仍然有越來越按鈕不在的WebView 1日URL功能相同的麻煩。當建議我試圖使用backButton.hidden我得到一個錯誤:請求成員'隱藏'不是結構或聯合。 感謝任何幫助,讓我的後退按鈕僅在webview'cangoback'時出現,並在不能出現時才顯示。 在編碼糟糕的邏輯我想是這樣的:後退按鈕=隱若webView的cangoBack = NO 歡呼球員蘭迪 我已經編輯inital問題,包括我的代碼。 – 2009-11-25 20:02:16