i have a view controller and in view did load method i have this code
- (void)viewDidLoad
{
self.navigationItem.title=#"Twitter Profile";
CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 370.0);
UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];
[webView setBackgroundColor:[UIColor whiteColor]];
NSString *urlAddress = #"http://twitter.com/#!/SummerApps";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
[webView release];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
in simulator everything works fine but on device the page just doesn't load.
I also have the same code on another view for facebook and it works fine the link is the only difference! Any help?
have you connected your webView with outlet connection ? or check your internet setting in Simulator.
Well when i open the same link with safari on my i-device pops up an alert that tells me that the certificate is not trusted if i click ok then it loads? Do you know whats going on i think that's why it doesn't load in my built in web view
Related
I'm using a small UIWebView, and scalesPageToFit doesn't work correctly for some url. (look like it cannot resize at 100%. (but if i zoom out the webview manually(gesture), it work!
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 400.0f)];
webViewT = [[UIWebView alloc] initWithFrame:view.bounds];
webViewT.delegate = self;
webViewT.scalesPageToFit = YES;
NSURL* url = [NSURL URLWithString:#"http://www.google.com/"];
[webViewT loadRequest:[NSURLRequest requestWithURL:url]];
Please note that i've found a solution:(below work, BUT I have the time to see a "resize"
- (void) webViewDidFinishLoad:(UIWebView *)webViewT {
if ([theWebView respondsToSelector:#selector(scrollView)])
{
UIScrollView *scroll=[theWebView scrollView];
float zoom=theWebView.bounds.size.width/scroll.contentSize.width;
[scroll setZoomScale:zoom animated:NO];
}
}
Any idea? Thanks!
In Some of cases this types of problem Generated. At that time java script use for control of Zoom of UIWebView, use following code.
NSString *jsCommand = [NSString stringWithFormat:#"document.body.style.zoom = 1.5;"];
[webLookupView stringByEvaluatingJavaScriptFromString:jsCommand];
Other way is
Refer this Answer UIWebView does not scale content to fit
How to I show website on my tab in application?
And create refresh button
Assuming you want to add a UIWebView to a UIViewController. Put this in your viewDidLoad method:
UIWebView *wv = [[UIWebView alloc] initWithFrame:self.view.frame];
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL urlWithString:#"www.google.com"]];
[wv loadRequest:req];
[self.view addSubview:wv];
Regarding the refresh button: Make sure 'wv' is defined in your .h file and use this method:
- (IBAction)refresh
{
[wv reload];
}
Actually i have one table view ,when Select rowAtIndexPath then it load my webView and play my video, how to return from UIWebView to my tableView ?
-(void)playButtonPressed1:(UIButton*)sender
{
Video *currentVideo= [[xmlParservideo videoNames] objectAtIndex:btn1.tag];
NSLog(#"content============== %#", [currentVideo content2]);
CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0);
UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];
[webView setBackgroundColor:[UIColor greenColor]];
NSString *urlString=currentVideo.content2;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[[self view] addSubview:webView];
// [self.navigationController popViewControllerAnimated:YES];
NSLog(#"jointed2 jjjjjjjjj %d",btn1.tag);
Place the Uiwebview in another view controller and push to it when a row is selected and when the video complete pop back to the tableview controller.
On didSelectRowAtIndexPath
videoViewController *newView = [videoViewController alloc]initWithNibName:#"videoViewController" bundle:nil];
[self.navigationController pushViewController:newView animated:YES];
and in your init method of the view controller create the webView programatically
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = #"Video Player";
UIWebView *videoWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 290)];
[videoWebView setDelegate:self];
NSString *urlAddress = #"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[videoWebView loadRequest:requestObj];
[[self view] addSubview:videoWebView];
}
return self;
}
Ok, Now just pop your view after completing your video
[self.navigationController popViewControllerAnimated: NO];
A workaround that may work is using this: [webView setHidden:YES];
This hides the webView from the view, so use that line of code whenever you want the webview to disappear. When you want it to return to the view, use this: [webView setHidden:NO];
I managed to show a UIWebView that shows content from the internet.
But apparently it does not rotate as it should:
http://www.youtube.com/watch?v=VV0BmNkSrvU
I'm using this code:
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window) {
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
}
_webView = [[UIWebView alloc] initWithFrame:rect];
_webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
NSURL* url = [[NSURL alloc] initWithString:URL]; NSURLRequest* request = [[NSURLRequest alloc] initWithURL:url];
[_webView loadRequest:request];
//Unity's UIView
UIView* subView = [window.subviews objectAtIndex:0];
[url release];
[subView addSubview:_webView];
It seems that this code has not been placed inside a UIViewController. Autorotation works correctly only inside a UIViewController. If you want to manage it outside a UIViewController you must observe all orientation change notifications and then transform your view accordingly.
I've to switch a part of my app: I will implement a web view insread of a picture (imageview).
So I tried to make it with the interface builder but there is too many errors so I prefer to use code!
for the pictures, I user those lines :
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
self.imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0,64,320,367);
[self.view addSubview:imageView];
[self.imageView release];
Now, I tried to use this code but nothing's showed:
#property (nonatomic, retain) IBOutlet UIWebView *webView;
...
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.fr"]]];
[self.view addSubview:webView];
If you know how to make .... would be nice for me,
THANKS!
Declare in your h file:
UIWebView *contentWebView;
And also tell to your viewController that you will implement <UIWebViewDelegate>
In viewDidLoad Add:
contentWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
contentWebView.delegate = self;
contentWebView.multipleTouchEnabled = YES;
contentWebView.scalesPageToFit = NO;
[self.view addSubview:contentWebView];
In dealloc don't forget to release the webView:
[contentWebView release];
And implement the delegate methods:
#pragma mark -
#pragma mark WebViewDelegates
- (void)webViewDidStartLoad:(UIWebView *)webView{
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
}
And also you need to load an request. You can doit in viewDidLoad after you have added the webView to your view:
[contentWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.apple.com/"]]];
adjust the frame as u needed and if add anything like imageview as subview to webview then u have to use bringsubviewtofront function.
- (void) initUIWebView {
NSLog(#"DetailViewController->initUIWebView {");
UIWebView *aWebView;
// init and create the UIWebView
aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
aWebView.autoresizesSubviews = YES;
aWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
//set the web view delegates for the web view to be itself
[aWebView setDelegate:self];
//Set the URL to go to for your UIWebView
NSString *urlAddress = #”http://www.google.com”;
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//load the URL into the web view.
[aWebView loadRequest:requestObj];
//add the web view to the content view
[self.view addSubview:aWebView];
[aWebView release], aWebView = nil;
}
- (void)viewDidLoad {
[self initUIWebView]; // <<<<<<<<<<<< this calls the UIWebView Function
[super viewDidLoad];
}