TableView中iOS显示的标题截断了titleForHeaderInSection返回的字符串

时间:2016-04-06 14:51:07

标签: ios swift uitableview

我试图从控制器构建一个tableView,而不是在故事板中自己构建静态单元格。我从数组中填充了所有单元格,我希望从不同的数组中显示节标题。 numberOfSections...返回5.我的titleForHeaderInSection方法如下:

override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return self.questions[section]
}

我的self.questions数组:

let questions = ["Have you had difficulties participating in normal training and competition due to ankle problems during the past week?",
    "To what extent have you reduced your training volume due to ankle problems during the past week?",
    "To what extent have ankle problems affected your performance in the past week?",
    "To what extent have you experienced ankle pain related to your sport during the past week?",
    "Finished?"];

出于某种原因,当我运行应用程序时,标题只有一行,因此没有显示我想要显示的完整问题。可能是什么导致了这个?基于其他问题和研究,我是否需要创建自己的视图?

2 个答案:

答案 0 :(得分:0)

默认导航顶部栏不会显示长的字符串。如果您不希望截断,您必须创建自己的自定义视图/顶部栏。

答案 1 :(得分:0)

也许实现func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?并返回一个带有标签的自定义标头。

如果您将此标签的约束(顶部,底部,左侧和右侧)设置为其超级视图,并实现func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat并计算字符串高度以返回正确的视图高度。