我一直在用从数据库中获取的数据填充 UITable View 单元格。不同单元格的数据长度不同。所以我需要根据数据长度扩展或收缩高度。目前,我正在使用带有以下代码的自定义单元格。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID= @"customcell4fan";
customcell4fan *cell = (customcell4fan *)[tableView dequeueReusableCellWithIdentifier:cellID];
if(cell==nil)
{
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"customcell4fan" owner:nil options:nil];
for(id currentObject in nibObjects)
{
if([currentObject isKindOfClass: [customcell4fan class]])
{
cell = (customcell4fan *)currentObject;
}
}
}
eleme = [xmlElementObjects objectAtIndex:indexPath.section];
NSString *email= [eleme.title stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" \n\t"]];
NSString *postData= [eleme.description stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" \n\t"]];
cell.nameLabel.text=email;
cell.postLabel.text=postData;
return cell;
}
最佳答案
试试这个 http://www.roostersoftstudios.com/2011/04/14/iphone-uitableview-with-animated-expanding-cells/ 我发现它很有帮助
关于iphone - 表格 View 单元格随文本大小展开或收缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9834423/