-3

UIWebView 1 でハイパーリンクをクリックしてから UIWebView 2 を開き、UIWebView 2 でハイパーリンクをクリックしてから UIWebView 3 を開き、UIWebView 3 でハイパーリンクをクリックしてから UIWebView 4 を開きます。

これを実装する方法は?

私は今、2番目のUIWebViewを開きます

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
self.otherWebView = [[UIWebView alloc] init];
    numberOfOpenedWebPage ++;
    self.otherWebView.tag = numberOfOpenedWebPage;

    self.otherWebView.delegate = self;
    CGRect frame = self.view.frame;
    self.otherWebView.frame = CGRectMake(frame.size.width, 0.0f, frame.size.width, frame.size.height);
    [self.view addSubview:self.otherWebView];
    [otherWebView loadRequest:request];

すべての新しい webview はデリゲート メソッドを共有する必要があるため、uiwebview var をクラス var として定義しました。しかし、私はより多くを作成する方法を知りませんshouldStartLoadWithRequest

ありがとう

4

1 に答える 1

1

現在のコードの問題は、ハイパーリンクがどこから開かれたかを確認していないことです。

この擬似コードに従ってコードを書き直す必要があります。

// Declare a NSMutableArray in the .h file to store all UIWebViews that are loaded this way.
// Assume that I can refer to it as self.allWebViews
// Set tag of the first UIWebView to 0, and put it in self.allWebViews

if (self.allWebViews.count <= webView.tag + 1) {
    Initialize a new UIWebView
    Set tag to self.allWebViews.count
    Add it to self.allWebViews
    Subview the UIWebView
    Set it to load NSURLRequest passed in
} else {
    Get the UIWebView from the (webView.tag + 1) position of the self.allWebViews
    Set the UIWebView to load the NSURLRequest passed in
}

// Never load hyperlink in the current web view
return NO;

UIWebViews は、NSMutableArray からの強い参照によって保持されていることに注意してください。あなたのプログラムがどのように機能するかはわかりませんが、UIWebView をもう使用しない場合は、これに注意して解放する必要があります。

于 2012-06-20T04:38:46.613 に答える