我收到一条内存警告:“对于标记行的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;
}
我将这个单独的类用于管理单元格以使其操作变得容易。
有人可以帮我解决这个问题吗?
提前完成。
答案 0 :(得分:1)
如果你为这两行发布initWithTitle的代码会更好:
[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;