本文介绍了创建UIWebView并以编程方式加载网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我的代码。我只是想加载一个网页并在屏幕上放一个后退按钮。不知道为什么屏幕上没有显示任何内容。
The following is my code. I simply want to load a website page and put a back button on screen. Don't know why nothing shows on the screen.
in .h
#import <UIKit/UIKit.h> @interface ThirdViewController : UIViewController { UIWebView *myWebView; } @property (nonatomic, retain) UIWebView *myWebView; -(IBAction)goBack:(id)sender; @endin .m
#import "ThirdViewController.h" @implementation ThirdViewController @synthesize myWebView; -(IBAction)goBack:(id)sender { [myWebView goBack]; } - (void)viewDidLoad { [super viewDidLoad]; NSString *urlAddress = @"www.apple"; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [myWebView loadRequest:requestObj]; [self.view addSubview:myWebView]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(goBack:)]; }推荐答案
初始化你的webView。
Initialize your webView.
UIWebView *tempWebview = [[UIWebView alloc]initWithFrame:theFrame]; NSString *urlAddress = @"www.apple"; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; self.myWebView = tempWebview; [tempWebview loadRequest:requestObj]; [tempWebview release]; myWebView.delegate=self;更多推荐
创建UIWebView并以编程方式加载网站
发布评论