2016-11-30 88 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方法。

希望這有助於解決您的問題