The official documentation tells me I've to do these 3 things in order to manage the my memory for "nib objects" correctly.
@property (nonatomic, retain) IBOutlet UIUserInterfaceElementClass *anOutlet;
"You should then either synthesize the corresponding accessor methods, or implement them according to the declaration, and (in iPhone OS) release the corresponding variable in dealloc."
- (void)viewDidUnload {
self.anOutlet = nil;
[super viewDidUnload];
}
That makes sense for a normal view. However, how am I gonna do that for a UITableView with custom UITableViewCells
loaded through a .nib-file?
There the IBOutlets
are in MyCustomCell.h (inherited from UITableViewCell), but that is not the place where I load the nib and apply it to the cell instances, because that happens in MyTableView.m
So do I still release the IBOutlets
in the dealloc
of MyCustomCell.m or do I have to do something in MyTableView.m?
Also MyCustomCell.m doesn't have a - (void)viewDidUnload {}
where I ca开发者_StackOverflown set my IBOutlets
to nil, while my MyTableView.m does.
Are your IBOutlets properties of the cell? If so then release them in MyCustomCell's dealloc method.
Make sure that you are following the guidelines for tableViews and calling dequeueReusableCellWithIdentifier: in tableview:cellForRowAtIndex. The tableView will release your custom cells when it no longer needs them. Assuming that you do not have any other references to your cells (you shouldn't) then dealloc will be called for the cell dequeued by the tableView.
精彩评论