gpt4 book ai didi

iphone - UILabel 的 numberOfLines 在单元格中不起作用

转载 作者:可可西里 更新时间:2023-11-01 03:54:57 29 4
gpt4 key购买 nike

全部,

我是 iPhone 编程的新手。在下面的代码中,我希望文本显示评论标签中的所有文本,但现在它正在截断它。 numberofLines 也不能正常工作。现在它正在这样做。 “我的名字是弗雷德,我还没死……”但我希望它显示全文“我的名字是弗雷德,我还没有死,所以让我活下去”,即使它必须在多行上。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;

cell = [self.allCells objectForKey:[NSNumber numberWithInt:indexPath.row]];

if(!cell)
{
cell = [[[NSBundle mainBundle] loadNibNamed:@"UserCell2" owner:nil options:nil] lastObject];
cell.backgroundColor = [UIColor clearColor];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[self.allCells setObject:cell forKey:[NSNumber numberWithInt:indexPath.row]];
}

GSAsynImageView *imgView = (GSAsynImageView*)[cell viewWithTag:1000];
UILabel *lblTitle = (UILabel*)[cell viewWithTag:1001];
UILabel *lblComment = (UILabel*)[cell viewWithTag:1003];
UILabel *lbltime = (UILabel*)[cell viewWithTag:1004];

//lblComment setLineBreakMode:NSLineBreakByWordWrapping];
//lblComment.numberOfLines = 0;
//lblComment.lineBreakMode = UILineBreakModeCharacterWrap;

if(self.arrComments.count==0)
{
imgView.hidden = YES;
lblTitle.text = nil;
lblComment.text = nil;
lbltime.text = nil;
if(indexPath.row==1)lblTitle.text = @"No comments yet";
}
else
{
imgView.hidden = NO;

NSDictionary *dcUser = [self.arrComments objectAtIndex:indexPath.row];

NSString *strBio = [dcUser objectForKey:@"CommentTxt"];
NSString *strDisplayName = [dcUser objectForKey:@"CommenterDisplayName"];

NSString *imgName = [dcUser objectForKey:@"ImageName"];
NSString *usernamex = [dcUser objectForKey:@"CommenterUserName"];

if([imgName isKindOfClass:[NSString class]])
{
if([imgName rangeOfString:@"facebook"].location!=NSNotFound || [imgName rangeOfString:@"twimg"].location!=NSNotFound)
[imgView loadImageFromPath:imgName];
else
[imgView loadImageFromPath:[NSString stringWithFormat:@"%@images/%c/%@/50x50%@",WEBSERVER,[usernamex characterAtIndex:0],usernamex,imgName]];
}

lblTitle.text = strDisplayName;
lblComment.text = strBio;
lbltime.text = [self getDateTitle:[dcUser objectForKey:@"Date"]];

}

return cell;
}

最佳答案

尝试下面的代码并添加到您的单元格中..

UILabel * lblTitle = [[UILabel alloc]init];
[lblTitle setFrame:CGRectMake(110, 31, 200, 50)];
lblTitle.text = @"your Text ";
lblTitle.lineBreakMode = UILineBreakModeWordWrap;// add this line
lblTitle.numberOfLines = 0;// add this line
lblTitle.font = [UIFont fontWithName:@"Helvetica" size:12];

有关更多详细信息,请参阅我的博客以及来自 THIS 的这篇文章链接

关于iphone - UILabel 的 numberOfLines 在单元格中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14950252/

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