以下是我的代码.我只是想加载一个网站页面并在屏幕上放一个后退按钮.不知道为什么屏幕上什么也没有显示.
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.
在.h中
#import <UIKit/UIKit.h>
@interface ThirdViewController : UIViewController
{
UIWebView *myWebView;
}
@property (nonatomic, retain) UIWebView *myWebView;
-(IBAction)goBack:(id)sender;
@end
在.m
#import "ThirdViewController.h"
@implementation ThirdViewController
@synthesize myWebView;
-(IBAction)goBack:(id)sender
{
[myWebView goBack];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlAddress = @"http://www.apple.com";
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 = @"http://www.apple.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
self.myWebView = tempWebview;
[tempWebview loadRequest:requestObj];
[tempWebview release];
myWebView.delegate=self;
这篇关于创建 UIWebView 并以编程方式加载网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!