views:

54

answers:

1

Hi,

I have the weirdest problem, I setup a UIWebView in the viewDidLoad section of my viewController and for some reaosn it keeps on looping through the setup :

- (void)loadView {


UIWebView *webViewer = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 430)]; 
webViewer.delegate = self;
webViewer.scalesPageToFit = YES;        
webViewer.dataDetectorTypes = UIDataDetectorTypeAll;
[[webViewer.subviews objectAtIndex:0] setBounces:NO];


NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
[webViewer loadRequest:[NSURLRequest requestWithURL:url]];
[self.view addSubview:webViewer];
    //at this point the app returns to the beginning of the UIWebView setup 
[webViewer release];  


} 

If I put the setup in the viewDidAppear section, it doesn't loop but after the setup is complete nothing happens.. The UIWebView is never added or loaded.

I have done this many times before and it has worked fine so I don't know why it isn't working this time.

A: 

You are assigning [self.view addSubview:webViewer]; but self.view is not created at all. hence looping so add below code first

UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
self.view = myView;
[myView release];

then your code.

UIWebView *webViewer = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 430)]; webViewer.delegate = self; webViewer.scalesPageToFit = YES;
webViewer.dataDetectorTypes = UIDataDetectorTypeAll;
[[webViewer.subviews objectAtIndex:0] setBounces:NO];

NSURL *url = [NSURL URLWithString:@"http://www.google.com/"]; [webViewer loadRequest:[NSURLRequest requestWithURL:url]];
[self.view addSubview:webViewer];
//at this point the app returns to the beginning of the UIWebView setup [webViewer release];

jeeva
Thank you. I Also realized that the reason this wasn't working when in viewDidAppear was because in my code (though not what I wrote above) I had @"www.google.com" instead of @"http://www.google.com/".
But the reason for looping and not loading the web-view is the above reason only.
jeeva
Yes that is correct