我有泄漏自定义单元格的问题。泄漏自定义单元格
在我重写的UITableViewController,我有,
- (UITableViewCell *)tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TwitterTweetTableCell *cell = nil;
// Obtain the cell...
cell = [[TwitterTweetTableCell alloc]
initWithTable:tableView
andTweet:[[self getTimeline] objectAtIndex:indexPath.row]];
return [cell autorelease];
}
,并在相应覆盖的UITableViewCell类,
- (TwitterTweetTableCell *) initWithTable:(UITableView *) tableView
andTweet:(NSDictionary *) tweet
{
tweetCell = nil;
// ************************************************************************************
// The identifier used in the following dequeue is the one set in the corresponding nib
// ************************************************************************************
tweetCell = (TwitterTweetTableCell *)
[tableView dequeueReusableCellWithIdentifier:@"tweetCell"]; // <-- set this in NIB
if (tweetCell)
{
NSLog(@"tweetCell: Reuse!");
}
if(!tweetCell)
{
NSArray *topLevelObjects = [[NSBundle mainBundle]
loadNibNamed:@"TwitterTweetTableCell" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[TwitterTweetTableCell class]])
{
tweetCell = (TwitterTweetTableCell *)currentObject;
break;
}
}
// yadda, yadda, yadda
[tweetCell retain];
}
return tweetCell;
}
有一个相应的NIB自定义单元格(TwitterTweetTableCell),并且指出在代码中,单元的标识符在那里设置为'tweetCell'。
代码工作,除了罚款,根据仪器,它泄漏细胞:-(
我相信我在小区为1的retainCount返回正确的(这是从页头返回而且,不管怎么说,如果我不将其与僵尸崩溃)。由于代码显示,我后来终于交给受表控制器之前自动释放它。
为什么这泄漏将不胜感激思考。
优秀!非常清楚,有启发性,最重要的是,它已经解决了这个问题。我从中学到了很多 - 谢谢你,yuji。 – Snips 2012-04-02 17:16:05