代码之家  ›  专栏  ›  技术社区  ›  neha

iphone中调用方此时不拥有的对象的引用计数的错误递减

  •  1
  • neha  · 技术社区  · 14 年前

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

    我制作了这个单独的类来管理单元格,使其操作更简单。

    提前告诉他。

    1 回复  |  直到 14 年前
        1
  •  1
  •   vodkhang    14 年前

    最好将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;