gpt4 book ai didi

ios - 自定义 UITableViewCells 重叠?

转载 作者:行者123 更新时间:2023-11-29 02:43:01 24 4
gpt4 key购买 nike

我有 5 种类型的自定义 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;
}

最佳答案

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

使用这个方法:

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

关于ios - 自定义 UITableViewCells 重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25520457/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com