views:

39

answers:

1

Hi all,

I'm getting a memory warning: "Incorrect decrement of the reference count of an object that is not owned at this point by the caller" for challengeCell at the marked line.

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;

EDIT:

 -(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;
}

I made this separate class for management of cell to make its manipulation easy.

Can anybody please help me resolve this?

Thanx in advance.

A: 

It will be better if you post your code for initWithTitle for these 2 lines:

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

But what I guess is that you already have a challengeCell object, already alloc-ed and init-ed. Your code looks really strange to be honest. Usually, what people do will be [[UIChallengeCell alloc] initWithTitle...] not from the instance itself. I think this creates your problem.

What you should do is set the property yourself.

challengeCell.challengeTitle = challengeTitle;
challengeCell.subTitle = challengeSubtitle;
vodkhang
Thanx for replying. I have edited my question to include my init method, which I created in the respective cell's class so that I can keep the cell interface logic separate.
neha
I think your method makes confusing. Why not name it `setTitle:subTitle:...` and return void. Then I think it will solve your problem
vodkhang
Yes, it did.. Thanx..
neha