gpt4 book ai didi

iphone - 打开从 UIWebView 到 Safari (iphone) 的链接

转载 作者:行者123 更新时间:2023-12-03 19:03:20 24 4
gpt4 key购买 nike

好吧,不要尝试用文字解释我的问题,请观看我录制的这个小视频 http://www.youtube.com/watch?v=fwb55jnZI6w

这是详细 View Controller 的代码(webview 所在的页面)

detailViewController.h

#import <UIKit/UIKit.h>
#import "MWFeedItem.h"
@interface DetailViewController : UIViewController <UIWebViewDelegate> {
MWFeedItem *item;
NSString *summaryString;
IBOutlet UILabel *titleLabel;
IBOutlet UIWebView *contentLabel;
//IBOutlet UILabel *dateLabel;
IBOutlet UIScrollView *textScroller;
}
@property (nonatomic, retain) MWFeedItem *item;
@property (nonatomic, retain) NSString *summaryString;
@property (nonatomic, retain) IBOutlet UILabel *titleLabel;
@property (nonatomic, retain) IBOutlet UIWebView *contentLabel;
@end

detailViewController.m

    #import "DetailViewController.h"
#import "NSString+XMLEntities.h"

typedef enum { SectionHeader, SectionDetail } Sections;
typedef enum { SectionHeaderTitle, SectionHeaderDate, SectionHeaderURL } HeaderRows;
typedef enum { SectionDetailSummary } DetailRows;



@implementation DetailViewController
@synthesize item, summaryString, titleLabel, contentLabel;


- (BOOL)webView:(UIWebView *)contentLabel shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType; {

NSURL *requestURL = [ [ request URL ] retain ];
// Check to see what protocol/scheme the requested URL is.

return [ [ UIApplication sharedApplication ] openURL: [ requestURL autorelease ] ];
return NO;
// Auto release
[ requestURL release ];
// If request url is something other than http or https it will open
// in UIWebView. You could also check for the other following
// protocols: tel, mailto and sms
}
- (void)viewDidLoad {

[super viewDidLoad];

/*if (item.date) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
self.dateString = [formatter stringFromDate:item.date];
[formatter release];
}*/

if (item.summary) {
self.summaryString = [[[item.summary stringByStrippingTags] stringByRemovingNewLinesAndWhitespace] stringByDecodingXMLEntities];
}

titleLabel.text = item.title ? item.title : @"[No Title]";
[titleLabel setBackgroundColor:[UIColor clearColor]];
//dateLabel.text = dateString ? dateString : @"[No Date]";
// Summary
NSString *HTMLData = summaryString;
[contentLabel loadHTMLString:HTMLData baseURL:[NSURL URLWithString: [NSString stringWithFormat:@"http://www.feed43.com/1515171705611023.xml"]]];

//Calculate the expected size based on the font and linebreak mode of your label
//CGSize maximumLabelSize = CGSizeMake(280,9999);

//CGSize expectedLabelSize = [summaryString sizeWithFont:contentLabel.font
//constrainedToSize:maximumLabelSize
//lineBreakMode:contentLabel.lineBreakMode];


//adjust the label the the new height.
//CGRect newFrame = contentLabel.frame;
//newFrame.size.height = expectedLabelSize.height;
//contentLabel.frame = newFrame;
[textScroller setCanCancelContentTouches:NO];
[textScroller setContentSize:CGSizeMake(320, 500)];
textScroller.indicatorStyle = UIScrollViewIndicatorStyleBlack;
textScroller.scrollEnabled = YES;
textScroller.clipsToBounds = YES;

//return titleLabel;
//return dateLabel;
//return contentLabel;

}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return NO;
}
- (void)dealloc {
[super dealloc];
}
@end

注意:尽管它写着“contentLabel”,但它是一个 UIWebView。它是旧版本遗留下来的

谢谢!

最佳答案

实现-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)请求navigationType:(UIWebViewNavigationType)navigationType
然后你可以做这样的事情:

NSURL* url = [request URL];
if (UIWebViewNavigationTypeLinkClicked == navigationType)
{
[[UIApplication sharedApplication] openURL:url];
return NO;
}

关于iphone - 打开从 UIWebView 到 Safari (iphone) 的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3201264/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com