2013-08-18 41 views
0

我创建了UIWebView的单一视图的应用程序在顶部导航栏,打开主页。在导航栏,我想创建一个按钮,其中,当被按下时,会带给你回到UIWebView的主页。目前,当我按下导航栏上的“主页”按钮,退出该应用程序,并让我在Safari中的URL。请帮我解决这个问题。我的代码如下:如何使在导航栏中圆矩形按钮中的UIWebView

ViewController.h:

@interface ViewController : UIViewController 
{ 
IBOutlet UIWebView *MyWebView; 
} 

//Buttons: 
-(IBAction)HomeButton; 

ViewController.m:

//Buttons: 
-(IBAction)HomeButton { 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://google.com"]]; 
} 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    NSURL *myURL = [NSURL URLWithString:@"http://google.com"]; 

    NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL]; 

    [MyWebView loadRequest:myRequest]; 
} 

回答

0

您必须加载URL在Web视图像你已经在做viewDidLoad调用,而不是openURL:

-(IBAction)HomeButton { 
NSURL *myURL = [NSURL URLWithString:@"http://google.com"]; 
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL]; 

[MyWebView loadRequest:myRequest]; 
} 

Btw。约定以小写字母开始您的属性名称。所以,你可能要重新命名MyWebViewmyWebView