【问题标题】:Incorrect decrement of the reference count of an object that is not owned at this point by the caller in iphoneiphone中调用者此时不拥有的对象的引用计数不正确递减
【发布时间】:2010-09-23 11:15:55
【问题描述】:

我收到内存警告:标记行中的 challengeCell 的“调用者此时不拥有的对象的引用计数不正确递减”。

myIdentifier = @"ChallengTblVwCell";    
ChallengeTableViewCell *challengeCell = (ChallengeTableViewCell *)[tableView dequeueReusableCellWithIdentifier:myIdentifier];
if( challengeCell == nil )
{
    [[ NSBundle mainBundle ] loadNibNamed:@"ChallengeTableViewCell" owner:self options:nil ];
    challengeCell = challengeTblCell; 
}

else {
//some code
}           
        challengeInstance = [genericArray objectAtIndex:indexPath.row];
        NSString *challengeTitle = challengeInstance.elecompany;

        [challengeCell initWithTitle:challengeTitle subTitle:challengeSubtitle _votes:challengeVotes content:challengeContent _time:challengeTime _image:challengeImage noComments:challengeCommentsNo]; //Warning coming at this line
        return (UITableViewCell *)challengeCell;

编辑:

 -(id)initWithTitle:(NSString *)_title content:(NSString *)_content fromName:(NSString *)_fromName _time:(NSString *)_time_ _image:(NSString *)_image_ noComments:(NSInteger)commentsNo
 {
    //Labels are created through interface builder

[_lbltitle_ setText:_title];       
[_lbltime setText:_time_];
[lblcontent setText:_content];
[lblsubTitle setText:_fromName];
[lblnoOfComments setText:[NSString stringWithFormat:@"%d",commentsNo]];

// code for adjusting label height according to content.

return self;
}

我为单元格的管理创建了这个单独的类,以便于对其进行操作。

谁能帮我解决这个问题?

提前感谢。

【问题讨论】:

  • initWithTitle 自定义方法是什么样的?

标签: iphone memory-management


【解决方案1】:

如果您将 initWithTitle 的代码发布在这 2 行中会更好:

[challengeCell initWithTitle:challengeTitle subTitle:challengeSubtitle _votes:challengeVotes content:challengeContent _time:challengeTime _image:challengeImage noComments:challengeCommentsNo]; //Warning coming at this line
return (UITableViewCell *)challengeCell;

但我猜你已经有一个challengeCell 对象,已经分配和初始化。老实说,您的代码看起来真的很奇怪。通常,人们所做的将是[[UIChallengeCell alloc] initWithTitle...] 而不是来自实例本身。我认为这会造成您的问题。

你应该做的是自己设置属性。

challengeCell.challengeTitle = challengeTitle;
challengeCell.subTitle = challengeSubtitle;

【讨论】:

  • 感谢您的回复。我已经编辑了我的问题以包含我在相应单元格的类中创建的 init 方法,以便我可以将单元格接口逻辑分开。
  • 我认为您的方法令人困惑。为什么不将其命名为 setTitle:subTitle:... 并返回 void。那我想它会解决你的问题
猜你喜欢
  • 2011-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多