Reputation: 6028
I am using loadNibNamed:owner:options:
as documented by Apple to load a custom UITableViewCell from a nib file:
ItemCell *cell = (ItemCell *)[tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil) {
// (1)
[[NSBundle mainBundle] loadNibNamed:@"ItemCell" owner:self options:nil];
// (2)
cell = self.itemCell;
self.itemCell = nil;
// (3)
// code continues here
}
And the class declaration of the view controller:
@interface MyViewController : UIViewController<UITableViewDelegate, UITableViewDataSource> {
@private
UITableView *tableView;
ItemCell *itemCell;
}
@property (nonatomic, retain) IBOutlet ItemCell *itemCell;
MyViewController is the File's Owner of the ItemCell.
I am observing the following:
self.itemCell
retain count is 0 self.itemCell
retain count is 2 self.itemCell
retain count is 0 cell
retain count is 1Could someone explain:
self.itemCell
retain count go from 2 to 0 between (2) and (3)?cell
in (3) equal to 1?Upvotes: 0
Views: 635
Reputation: 162722
As for the answer to your two questions, "implementation detail".
As long as you balance your retains and releases, your job is done. Explaining why the retain count is any given absolute value would require access to the implementation of the frameworks themselves.
Upvotes: 3
Reputation: 6028
Ooops, made a mistake, in (3)
In (3) I was calling [self.itemCell retainCount]
to view the retain count but since self.itemCell
was set to nil
already , all I was getting was 0 obviously!! Not sure how I missed that...
in (3), cell
retain count is 1 which is normal (the cell is retained by the array returned by loadNibNamed:owner:options:
)
Upvotes: 0