Iphone 如何设置表格视图单元格以调整为标签?

Iphone 如何设置表格视图单元格以调整为标签?,iphone,xcode,swift,uitableview,label,Iphone,Xcode,Swift,Uitableview,Label,我正在使用Xcode制作一个应用程序。使用自动布局,我有一个包含在容器视图中的tableview,它是嵌入导航控制器的视图控制器的一部分 此表视图是我的内容页,因此各个表视图单元格将导致另一个表视图,其中包含我要显示的大部分信息 我为每个tableview单元格添加了包含一段文字的UIlabel,并为相应的tableview单元格设置了约束 在故事板中,必须能够看到所有段落,这看起来还不错。我已将行设置为0,并将换行 当我使用4s模拟器运行程序时,表格视图单元格不会显示整个段落,而是在每个段落的

我正在使用Xcode制作一个应用程序。使用自动布局,我有一个包含在容器视图中的tableview,它是嵌入导航控制器的视图控制器的一部分

此表视图是我的内容页,因此各个表视图单元格将导致另一个表视图,其中包含我要显示的大部分信息

我为每个tableview单元格添加了包含一段文字的UIlabel,并为相应的tableview单元格设置了约束

在故事板中,必须能够看到所有段落,这看起来还不错。我已将行设置为0,并将换行

当我使用4s模拟器运行程序时,表格视图单元格不会显示整个段落,而是在每个段落的末尾显示“…”

如何设置这些设置,使tableview单元格在经过文字包装后,根据UIlabel进行自我调整,以提供特定的手机屏幕尺寸

PS:我是SWIFT编程新手,感谢您花时间帮助我

你这样做了吗?:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}
这是自调整表视图单元格大小所必需的。还要确保以下事项:

a)
UILabel
的行数设置为0

b) “表格视图”单元中的“自动布局”系统是正确的--所有视图都固定在所有侧面,并且“自动布局”可以准确确定单元的高度


c) 为了提高效率,也要做一个
tableView.estimatedRowHeight=75
(或您的估计高度)

在viewDidLoad方法中添加这两行,并将行数标注为0,且不给出任何高度

func viewDidLoad() {
    super.viewDidLoad()

    tableView.estimatedRowHeight = 44.0
    tableView.rowHeight = UITableViewAutomaticDimension

}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell
    //cell.customTexLabel Number 0f lines 0 and dont give height contrains just Leading,Trailing,TOP and Bottom. 
    cell.customTextLable?.text = "Here index starts from 0 which means first element can be accessed using index as 0, second element can be accessed using index as 1 and so on. Let's check following example to create, initialize and access arrays:Here index starts from 0 which means first element can be accessed using index as 0, second element can be accessed using index as 1 and so on. Let's check following example to create, initialize and access arrays:Here index starts from 0 which means first element can be accessed using index as 0, second element can be accessed using index as 1 and so on. Let's check following example to create, initialize and access arrays:"

    return cell
}

您好@Daniel您可以学习如何创建自调整大小的单元格这里是自定义动态单元格的演示教程