2016-11-30 90 views
1

这个程序是只为研究和学习的目的。我是新开发的,所以没有什么特别的。TitleForHeaderInSection不正确显示

应该有一些接触,被分成两个不同的类别显示TableView中:最近&朋友

然而,当我尝试返回那些被作为标题显示(一切工作只是因为我打算它)与TitleForHeaderInSection函数,最终只显示一个。 (我使用了开关功能,因此,只有情况0正在显示)。

override func numberOfSections(in tableView: UITableView) -> Int { 

    return 2 // Recent & Friends 

} 

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 

    switch section { 

    case 0: return "RECENT" 

    case 1: return "FRIENDS" 

    default: break 

    } 

    return String(section) 
} 

enter image description here

正如截图上面看到,在应用程序只有两种情况之一被退回,我真的在努力找出原因。

+0

它的工作对我来说,你是如何创造你的头? – Rajat

+0

重写func tableView(_ tableView:UITableView,titleForHeaderInSection节:Int) - > String? { 开关部{ 情况下0:返回 “近期” 壳体1:返回 “FRIENDS” 默认:打破 } 返回字符串(部分) } –

回答

0

是显示部分或部分缺失,而不仅仅是标题,如果部分丢失,那么需要选择在故事板

+0

它仅仅是示出从所述一个部switch语句,这是问题,因为我想要两个。 (见主要帖子中的截图)... –

0

其分组的tableview风格,因为你力实现这些代表:(1)viewforHeaderInSection(2) heightForHeaderInSection

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 

    //Create label which you want to show on each section header and return it 

} 

还可以使用heightForHeaderInsection方法。

希望这有助于解决您的问题