开发者

how to open a link in uiwebview in a part of the page?

I am right now making one application where in one page i am having navigation bar with back button and a uiwebview. on clicking a button,this page should be loaded. My problem is that when this page is loaded, it covers the whole page with the url passed and is not limited to that p开发者_Python百科articular uiwebview. and as a result, i am not able to navigate to some other page.

I used the following code for the same :

- (void)viewWillAppear:(BOOL)animated
{
  NSString *url = [NSString stringWithFormat:@"http://www.facebook.com/"];

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
 [webview loadRequest:request];

 [super viewWillAppear:animated];
}

Can anybody answer me,how to ressolve this problem?

Thanks in advance.


When you use: [[UIApplication sharedApplication] openURL... it's calling safari to open the url, after it closes your app.

So, create a WebViewController and in the viewDidLoad add the following:

NSString *urlAddress;
if(siteType == @"facebook"){
  self.title = @"Facebook";
  urlAddress = @"http://www.facebook.com";
}

//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];

//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

//Load the request in the UIWebView.
[webView loadRequest:requestObj];

and in the root controller's button add this to the action:

WebViewController *wvc = [WebViewController alloc];
wvc.siteType = @"facebook";
[self.navigationController pushViewController:wvc animated:YES];

And of course for WebViewController header, you need:

@interface WebViewController : UIViewController <UIWebViewDelegate>
{
    NSString *siteType;
    IBOutlet UIWebView *webView;
}
@property (nonatomic, retain) NSString *siteType;
@property (nonatomic, retain) UIWebView *webView;
@end

and dont forget to @synthesize siteType,webView;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜