I’m creating a new UIViewController with 2 properties :
@property (retain, nonatomic) NSURL *url;
@property (retain, nonatomic) NSString *title;
and synthetised :
@synthesize url = _url;
@synthesize title = _title;
in my custom init method i’m not using the setter like the Memory Management Guide says but when I need to use the properties in the viewDidLoad, the url seems empty, the title doesn’t
- (id)initWithURL:(NSURL *)url andTitle:(NSString *)titleTemp
{
self = [super initWithNibName:@"navigatorViewController" bundle:nil];
if (self) {
_url = url;
_title = titleTemp;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[_titreBarButtonItem setTitle:_title];
NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:_url];
[_webView loadRequest:urlRequest];
[urlRequest release];
}
I can see my title but my web view is blank.
If I use self.url in the init, it’s working !
Do you have an idea ?
PS : Here’s how I call my init :
NSString *urlString = [[[NSBundle mainBundle] pathForResource:@"infos" ofType:@"html"] copy];
NSURL *url = [[NSURL alloc] initFileURLWithPath:urlString];
[urlString release];
navigatorViewController *navigatorVC = [[navigatorViewController alloc] initWithURL:url andTitle:@"Infos"];
[url release];
[self presentViewController:navigatorVC animated:YES completion:nil];
[navigatorVC release];
Thanks a lot
You must retain the URL either using :
in the init method or call the retain after assigning the url in the init method like this.