自定义UITableViewCells重叠?

时间:2014-08-27 06:40:16

标签: ios objective-c uitableview

我有5种类型的Custom UITableViewCell。我的numberofrows也正确。但是当涉及到显示。最后2个单元格互相攻击。 This is the method i am using to display the cells for the indexpath row. every if statement is working properly. as i checked with NSlog in it .

enter image description here

 if (indexPath.row == 0) {
            TaskDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TaskDetail" forIndexPath:indexPath];

        [cell.assignTo setText:@"  Lalu • Aug 30 , 2014  "];
        [cell.taskname setText:task_name];
        [cell.comments_countLbl setText:comments_count];
        // Configure the cell...
        NSLog(@"Cell Type %@",@"Task Detail");
        return cell;
    }

    else if (![comments[indexPath.row] isEqual:[NSNull null]] && ![imagecomments[indexPath.row] isEqual:[NSNull null]]) {
        Image_Text_Commet_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"image_text_comment" forIndexPath:indexPath];
        [cell.commentText setText:[comments objectAtIndex:indexPath.row]];

        NSString *imageURL = [imagecomments objectAtIndex:indexPath.row];
        NSString *convertURltoImage = [NSString stringWithFormat:@"%@%@",@"http://localhost:3001/",imageURL];
        NSURL *url = [NSURL URLWithString:convertURltoImage];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        UIImage *placeholderImage = [UIImage imageNamed:@"placeholder"];

        __weak Image_Text_Commet_TableViewCell *weakCell = cell;

        [cell.imageComment setImageWithURLRequest:request
                              placeholderImage:placeholderImage
                                       success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {

                                           weakCell.imageComment.image = image;
                                           [weakCell setNeedsLayout];

                                       } failure:nil];
        NSLog(@"Cell Type %@",@"Image and Text");

        return cell;

    }

    else if (![imagecomments[indexPath.row] isEqual:[NSNull null]] && [comments[indexPath.row] isEqual:[NSNull null]]){
        ImageCommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ImageComment" forIndexPath:indexPath];
        NSString *imageURL = [imagecomments objectAtIndex:indexPath.row];
        NSString *convertURltoImage = [NSString stringWithFormat:@"%@%@",@"http://localhost:3001/",imageURL];
        NSURL *url = [NSURL URLWithString:convertURltoImage];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        UIImage *placeholderImage = [UIImage imageNamed:@"placeholder1"];

        __weak ImageCommentTableViewCell *weakCell = cell;

        [cell.imageComment setImageWithURLRequest:request
                                 placeholderImage:placeholderImage
                                          success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {

                                              weakCell.imageComment.image = image;
                                              [weakCell setNeedsLayout];

                                          } failure:nil];
        NSLog(@"Cell Type %@",@"Image Only");


        return cell;
    }

    else if ([imagecomments[indexPath.row] isEqual:[NSNull null]] && ![comments[indexPath.row] isEqual:[NSNull null]]){
        CommentTaskTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"commentText" forIndexPath:indexPath];
        [cell.memberComment setText:[comments objectAtIndex:indexPath.row]];
        NSLog(@"Cell Type %@",@"Text Only");

        return cell;
    }

    else {

        AddCommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Addcomment" forIndexPath:indexPath];
        NSLog(@"Cell Type %@",@"Add Task Only")![This is the method i am using to display the cells for the indexpath row. every if statement is working properly. as i checked with NSlog in it .][3];

        return cell;
    }

1 个答案:

答案 0 :(得分:1)

您需要动态设置单元格的高度,这可能是问题

使用此方法:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
  CGFloat rowHeight = [self getRowHeightForRow: indexPath.row];
  return rowHeight;
}