2012-12-27 44 views
1

我是objective-c的新手,並且已經連續數週陷入這個問題。所以,將不勝感激任何幫助。無法在現有的UIWebView中顯示新頁面

我正在開發一個具有選項卡視圖的I-phone應用程序,其中一個選項卡是UIWebView。另一個選項卡提供了一種方法來選擇應在UIWebView中顯示的內容。

我可以顯示在UIWebView中(在viewDidLoad中)與初始視圖:

[self.groupWebView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]]; 

即工作得很好。

但是,當用戶在表視圖上選擇一些內容時,它必須在現有的UIWebView中打開一個新頁面。

所以我有這樣的:

-(void) displayGroup:(int)theGroup 
{ 
    // Set our selves to the webviews delegate since we implement the delegate methods here 
    self.groupWebView.delegate = self; 

    // Load it to the webview 

    NSString *html = @"<html><head><title>it worked...</title></head><body><a href=\"custom://THIS_IS_CUSTOM_LINK\">Click for custom link</a><br><a href=\"http://google.com\">it worked...</a></body></html>"; 
    [self.groupWebView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]]; 

} 

我把這個和它的運行,但什麼也沒有發生在Web視圖。

.h文件看起來像:

// PBGroupViewController.h 

#import <UIKit/UIKit.h> 

@interface PBGroupViewController : UIViewController <UIWebViewDelegate, UIScrollViewDelegate> 

@property (nonatomic, retain) IBOutlet UIWebView *groupWebView; 
- (void) displayGroup:(int)theGroup; 

@end 

任何幫助就這將是非常不勝感激...謝謝。

+1

確認您的webView不是無 – Misha

+0

webView正在顯示初始頁面,因此我認爲它不是無用的。但我不認爲這個函數displayGroup實際上是連接到webView。我對此很陌生,錯過了一些我認爲的東西。也許displayGroup函數應該將webView作爲函數的參數之一?我不知道...但我認爲我沒有連接到webView ... – madhu

回答

0

更改displayGroup功能是這樣的:

-(void) displayGroup:(int)theGroup 
{ 
    // Set our selves to the webviews delegate since we implement the delegate methods here 
    self.groupWebView.delegate = self; 

    // Load it to the webview 

    NSString *html = @"<html><head><title>it worked...</title></head><body><a href=\"custom://THIS_IS_CUSTOM_LINK\">Click for custom link</a><br><a href=\"http://google.com\">it worked...</a></body></html>"; 
    [self.groupWebView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]]; 
    [self.groupWebView stopLoading ]; 
    [self.groupWebView reload]; 
} 
+0

仍然沒有做任何事情。 webview只停留在初始頁面上。沒有任何更改... – madhu

0

時產生的表視圖用戶點擊某些URL ....如果是的話,那麼你應該使用didSelectRowAtIndexPath方法和你應該加載的網頁視圖..

+0

它將從程序生成的html文本字符串加載,而不是url。目前該程序正在調用displayGroup函數,該函數在正確的時間運行,但它不會在UIWebView中顯示任何內容。所以我們必須找出爲什麼displayGroup函數不能正常工作.... – madhu