2013-10-29 43 views
0

我在我的應用程序中遇到了非常奇怪的問題。我正在動態創建表格視圖單元格。並根據內容調整單元格標籤的高度。我的問題是,我的單元格標籤沒有顯示包裝後的最後一行,意思是如果我的標籤共有三行,那麼標籤只顯示兩行。該代碼在iOS6上工作,但在iOS 7上卻出現問題。任何幫助將不勝感激。表格單元標籤不包裹iOS7中的最後一行

[labelCell.contentView bringSubviewToFront:labelCell.textLabel]; 
labelCell.textLabel.numberOfLines = 0; 
labelCell.textLabel.lineBreakMode = NSLineBreakByWordWrapping; 
NSString *fieldLabel = labelCell.textLabel.text; 
CGSize textSize = [self sizeForLabelWithString:fieldLabel width:600.0f andIndexPath:indexPath]; 
float newHeight = textSize.height+22.0f; 
labelCell.height = newHeight; 
+0

只要採取在小區設置文本,高度動態的UILabel與沒有它的線。 –

+0

您在哪裏設置該標籤的文字? – Ganapathy

+0

其實我正在使用sensible tableview,我使用labelcell。 – nikBhosale

回答

0

您將根據內容更改標籤高度。因此,您需要動態處理單元格高度或需要根據內容(字符串中的最大值)設置單元格的高度。 即

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
return MAXStringHeght; 
} 

並嘗試一次。

+0

嘿,謝謝你的回覆,但它不是高度問題,因爲即使我將高度設置爲100,它也只是增加了單元格的高度,但在包裝後不顯示最後一行標籤。 – nikBhosale

1

使用這種方法:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *fieldLabel = labelCell.textLabel.text; 

    CGSize textSize = [fieldLabel sizeWithFont:[UIFont fontWithName:@"Georgia" size:17.0f] constrainedToSize:CGSizeMake(600, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping]; 
    float newHeight = textSize.height+22.0f; 
    return newHeight; 
} 

添加以下代碼的cellForRowAtIndexPath

UILabel *lblfield=[[UILabel alloc] init]; 
NSString *fieldLabel=[NSString stringWithFormat:@"%@",labelCell.textLabel.text]; 
CGSize textSize = [fieldLabel sizeWithFont:[UIFont fontWithName:@"Georgia" size:17.0f] constrainedToSize:CGSizeMake(600, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping]; 
float newHeight = textSize.height+22.0f; 
lblfield.frame=CGRectMake(10, 0, 600, newHeight); 
lblfield.backgroundColor=[UIColor clearColor]; 
lblfield.text=strusername; 
[cell addSubview:lblfield]; 
+0

'sizeWithFont:...'在ios7中被棄用,所以這個答案不會解決他的問題... –

+0

@ Mr.T Use -boundingRectWithSize:options:attributes:context:for iOS 7. –

+0

參考這個:http ://stackoverflow.com/questions/18315441/with-what-should-i-replace-the-deprecated-sizewithfontcontrainedtosizelinebrea –

1

我有同樣的問題,只是碰到這種偶然。我的標籤正在調整到正確的大小,但它沒有顯示任何標籤上的最後一行,它們被包裝成多行。而且,當我選擇/取消選擇單元格時,我可以突然看到最後一行。

我能夠通過給我的細胞的高度添加一個小巧的因子(2分)來解決這個問題。我更新的價值要使用的電池從高度:

return labelHeight + 2 * kTopAndBottomPadding; 

到:

return labelHeight + 2 * kTopAndBottomPadding + 2.f; 
相關問題