自定义UITableviewCell中的多个标签行 [英] Multiple lines of a label in a custom UITableviewCell

查看:118
本文介绍了自定义UITableviewCell中的多个标签行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经四处寻找我的问题的任何提示。但我无法找到解决方案。

I have searched around for any tip for my problem. But I cannot find a solution for this.

我已经创建了UITableviewCell(FeedCell)的子类。有一个图像和两个标签。
问题是我需要多线的标签不会出现多线。

I have made a subclass of UITableviewCell (FeedCell). With one image and two labels. The problem is that the label I need to be multiline does not show up with multilines.

我使用autolayot。

I use autolayot.

这是一个显示用户twitterfeed的应用程序。

This is an app who display the users twitterfeed.

我的代码:

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

FeedCell *tweetCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (tweetCell == nil) {
    tweetCell = [[FeedCell alloc]
            initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    [tweetCell.tweetText setNumberOfLines:0];
    [tweetCell.tweetText setLineBreakMode:NSLineBreakByWordWrapping];
    [tweetCell.tweetText setFont:[self fontForCell] ];


}
NSDictionary *tweet = _dataSource[[indexPath row]];

NSString *tweetString = [tweet valueForKey:@"text"];

tweetCell.name.text =[tweet valueForKeyPath:@"user.name"];


[tweetCell.tweetText setText:tweetString];

return tweetCell;

}

我还设置了heigthforRowAtIndexPath:

I have also set the heigthforRowAtIndexPath:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *tweet = _dataSource[[indexPath row]];
NSString *theText=[tweet valueForKey:@"text"];
UIFont *cellFont = [self fontForCell];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
CGSize labelSize = [theText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:NSLineBreakByWordWrapping];

return labelSize.height + 20;

}

问题在于tweet cell.tweetText不显示多行。我没有尝试过另一个CellStyle(我使用自定义cellstyle)。

The problem is that the tweet cell.tweetText does not show up with multilines. I have not tried this with another CellStyle (I use custom cellstyle).

有人提示吗?

推荐答案

我知道这是一篇旧帖子,但是在我搜索时就出现了。

I know this is an old post, but it came up when I was searching.

我通过以下 http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout

我认为对于iOS8,需要以下内容:

I think for iOS8 the following is required:


  • 将行设置为0

  • 设置自动换行

  • 将标签大小设置为> = 20

  • 确保有足够的约束来确定单元格高度(高度)标题和垂直间距)

  • Setting the lines to 0
  • Setting the word wrap
  • Setting the label size to be >= 20
  • Making sure there are enough constraints to determine the cell height (height of title and vertical spacing)

这篇关于自定义UITableviewCell中的多个标签行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆