I have recently began creating iOS applications completely programmatically (without the interface builder) and was wondering if there was any advantage/difference in declaring a ViewController’s view as a property before using it versus simply creating at the loadview function. Also, would I dealloc the view inside of the controllers dealloc if I am using it as a property?
i.e. this
- (void)loadView
{
_rootView = [[RootView alloc] initWithFrame:CGRectZero];
[self setView:self.rootView];
}
vs.
- (void)loadView
{
RootView *rootView = [[RootView alloc] initWithFrame:CGRectZero];
[self setView:rootView];
[rootView release];
}
viewalready is a property ofUIViewController. Declaring an extra property such asrootViewin your example would be pointless. So your second example would be the way to go. (I’m not sure why you’d want to create a view with a width and height of zero, but that’s another story.)In this case, your
deallocimplementation (if you provide one) should call[super dealloc]to ensure that theviewproperty is sent areleasemessage, but of course you should always call[super dealloc]in any overridden implementation ofdealloc.