I created a subclass of UITableView and wanted to use it with a UITableViewController to get the benefits of auto-scrolling when the keyboard appears. In the loadView for my view controller (derived from UITableViewController) I did the following:
- (void)loadView
{
[super loadView];
self.tableView = [[MyCustomTableView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
}
Shouldn’t this cause a leak with whatever self.tableView was referencing before the reassignment? I ran Build And Analyse and it didn’t report it as a leak.
However, if I try to “be good”…
- (void)loadView
{
[super loadView];
[self.tableView release];
// reassign code...
}
…all sorts of nasty crashes happen when my view is displayed. Can anyone explain to me whether simple reassignment causes a leak and, if so, how to do this properly?
Thanks in advance.
No, it won’t cause a leak because the setter method
setTableView:(which is called when you assign a new value to the property) will automatically release the old value. This is what properties are for.