0

設定に InAppSettingsKit を使用しており、テーブル ビューのフッターに会社のハイパーリンクを追加したいと考えています。セクション ヘッダー (テーブル ビューの下部にあり、フッターとして表示されます) に uiwebview を正常に追加しました。Web ビューにはハイパーリンクが表示されますが、タッチに反応しません。

Web ビューは、settingsViewController:tableView:viewForHeaderForSection で作成されます。

    UIView *containerView = [[UIView alloc] init];
    containerView.backgroundColor = [UIColor clearColor];
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(30, 0, self.view.frame.size.width-60, 35)];
    webView.delegate = self;
    NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:NSYearCalendarUnit fromDate:[NSDate date]];
    NSUInteger fontSize = 13;

    NSString *link = @"<a href=\"http://www.google.com\">My Hyperlink</a>";
    [webView loadHTMLString:[NSString stringWithFormat:@"<html><head></head><body style=\"font-family: sans-serif;font-size:%dpx;\"> <center>Copyright © %d %@</center></body></html>", fontSize, dateComponents.year,link]  baseURL:nil];
    webView.backgroundColor = [UIColor clearColor];
    webView.opaque = NO;
    [containerView addSubview:webView];
    return containerView;

および uiwebview デリゲート メソッド:

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
DDLogVerbose(@"Web view should start load with request %@. InType: %d", inRequest.URL.absoluteString, inType);
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
    [[UIApplication sharedApplication] openURL:[inRequest URL]];
    return NO;
}

return YES;

}

タッチが機能しない理由を誰か教えてもらえますか?? ところで... webView:shoudStartLoadWithRequest: テーブルビューがロード/表示されるとすぐに呼び出されます

どうも!

4

3 に答える 3

1

あなたのコードでは、フレームがなく、webview に適切なフレームを設定していないコンテナ ビューの 2 つの問題が見つかりました。

UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(30, 0, 100, 35)];
于 2013-06-19T14:07:26.423 に答える
0

代替手段: iOS 7 以降、UIKit/NSAttributedString は NSLinkAttributeName をサポートし、HTML の基本的なインポートも行います。したがって、UIWebView の代わりに UITextView をテーブル ビューのヘッダー/フッターとして使用できます。

HTML をインポートする-[NSAttributedString data:options:documentAttributes:]には、オプションとともに使用しNSDocumentTypeDocumentAttribute: NSHTMLTextDocumentTypeます。

NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)};
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithData:data options:options documentAttributes:NULL error:NULL];

UITextView *textView = [[UILabel alloc] initWithFrame: ...];
textView.editable = NO;
textView.scrollEnabled = NO;
textView.textContainerInset = UIEdgeInsetsZero; // optional
textView.attributedText = attributedText;

[UILabel はハイパーリンクを表示しますが、クリックできません。UILabel と NSLinkAttributeName を参照してください: リンクはクリックできません

于 2015-10-19T22:26:41.270 に答える
0

その理由は、IASKSettingsDelegate メソッドの settingsViewController:tableView:heightForHeaderForSection: がその特定のセクションに対して 0 を返したためです。uiwebview の高さと同じ高さを返すと、問題が解決しました。

于 2013-06-19T16:20:07.437 に答える