UITableView 自定义cell 方法

// 自定义 cell

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    NSString *identifier = @"Cell";

    

    UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:identifier];


    if (cell == nil) {

        

        cell = [[[UITableViewCell  alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease] ;

        

        //自定义 cell的背景

        UIImageView *backImageView = [[UIImageView  alloc] initWithFrame:CGRectMake(0, 0, cell.width, cell.height)];

        [backImageView setImage:[UIImage imageNamed:@"tck_on3.png"]];

        backImageView.tag = 201;

        

        cell.selectedBackgroundView = backImageView;

        [backImageView  release];

        

        // 自定义评分Label

        UILabel *RatingLabel = [[UILabel  alloc] initWithFrame:CGRectMake(160, 0, 40, cell.height)];

        RatingLabel.text = @"";

        RatingLabel.textColor = [UIColor  whiteColor];

        RatingLabel.backgroundColor = [UIColor  clearColor];

        RatingLabel.font = [UIFont systemFontOfSize:14];

        RatingLabel.tag = 202;

        

        [cell.contentView  addSubview:RatingLabel];

        [RatingLabel  release];

        

    }

    

    // 获得评分 label

    UILabel *label = (UILabel *) [self  viewWithTag:202];

    label.text = [[self.data  objectAtIndex:indexPath.rowobjectForKey:@"rating"];

    

    

    // 电影名称

    cell.textLabel.text = [[self.data  objectAtIndex:indexPath.rowobjectForKey:@"title"];

    cell.textLabel.textColor = [UIColor  whiteColor];

    cell.textLabel.font = [UIFont systemFontOfSize:14];

    cell.textLabel.highlightedTextColor = [UIColor blackColor];

    

    return cell;

}


做一个顶天立地的男子,并且自信,健康微笑的生活下去!
原文地址:https://www.cnblogs.com/luoxiao1115/p/2819501.html