views:

24

answers:

1

Hey guys,

This time, I was wondering when I was supposed to set my properties ...

I got a nav bar which I use to push a new controller (controlling a Web View) :

NewsViewController *webViewController = [[NewsViewController alloc] init]; // I create my controller

webViewController.urlText = @"http://www.google.fr"; // I set the property

InfonulAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 

[delegate.newsNavController pushViewController:webViewController animated:YES];

[webViewController release];

I don't know why but the code below doesn't work :

- (void)viewDidLoad { //viewDidLoad from my webViewController

   [super viewDidLoad];

   //Create a URL object.
   NSURL *url = [NSURL URLWithString:urlText];
   //URL Requst Object
   NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

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

I just want to create a UIWebView but I need to give the controller the URL to use !

Any idea where and when my urlText property needs to be set ?!?

Cheers,

Gauthier

A: 

Do you use property correctly? Like

@property(nonatomic,retain) NSString *urlText;

If so, try to use a customized init method like this;

-(id)initWithUrl:(NSString *)url
{
     if(self = [super init])
     {
          self.urlText = url;

     }
     return self;
}

dont forget to release urlText in dealloc. Now use;

NewsViewController *webViewController = [[NewsViewController alloc] initWithUrl:@"someUrl"];
EEE