UITableViewCell标签

时间:2015-01-28 19:33:10

标签: ios objective-c uitableview

我在单元格中显示标签时遇到问题。我必须制作一些标签,例如cell.textLabel,但要使用其他width和其他来源x。我有很多单元格,每个单元格都有不同的文本(它在数组中)。当我使用原始textLabel(不幸的是原始xwidth)时,一切正常,但是当我添加标签时:

CGRect frame;
CGFloat height = [self tableView heightForRowAtIndexPath:indexPath];
frame = CGRectMake(15, 0, 220, height);
UILabel *message = [[UILabel alloc]initWithFrame:frame]

[tableView heightForRowAtIndexPath:indexPath]我有一种根据文本计算height的方法(在原作的textLabel中)。

消息总是处于不良位置,另一方面是消息等。 cellForRow代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"SimpleTableItem";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}

CGRect frame;
frame = CGRectMake(15, 0, 220, 9999);

UILabel *message = [[UILabel alloc]initWithFrame:frame];
message.numberOfLines = 0;
message.tag = indexPath.section;
message.lineBreakMode = UILineBreakModeWordWrap;
message.font = [UIFont fontWithName:@"Futura" size:13];

message.text = @"some text";
[message sizeToFit];
[cell.contentView addSubview:message];
cell.imageView.frame = CGRectOffset(cell.frame, 10, 10);
[cell sizeToFit];
return cell;}

准备好:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section!=0){
for(int i = 1;i<indexPath.section;i++)
{
    [[cell.contentView viewWithTag:indexPat.section-i]removeFromSuperview];
}
}

}

0 个答案:

没有答案