【发布时间】:2013-02-19 05:09:58
【问题描述】:
全部,
我对 iphone 编程非常陌生。在下面的代码中,我希望文本显示注释标签中的所有文本,但现在它正在截断它。 numberofLines 也无法正常工作。现在它正在这样做。 “我的名字是 Fred,我还没有死……”但我希望它显示全文“我的名字是 Fred,我还没有死,所以让我活着吧”,即使它必须在多行中。
- (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;
}
【问题讨论】:
-
你应该使用 UITextView 来显示多行而不是 UIlabel
-
请确保您的标签有足够的垂直空间,否则即使设置多行也会截断。
-
增加标签的宽度然后检查是否。行数= 0...
-
这不是真的。 :P ;)
标签: iphone ios uitableview uilabel ios6