2017-05-06 53 views
0

我试图创建一个使用swift 3 UITableViewController的产品列表,但部分显示在产品列表之后。一定有什么东西我失踪,找不到任何地方Swift 3 UITableView部分显示在列表后

下面是一个简单的代码

let data = [["0,0", "0,1", "0,2"], ["1,0", "1,1", "1,2"], ["2,0", "2,1", "2,2"], ["3,0", "3,1", "3,2"]] 

override func numberOfSections(in tableView: UITableView) -> Int { 
    return data.count//productCategoriesSections.count 
} 

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return data[section].count//productCategories[section].count 
} 


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "defaultCategoryCell", for: indexPath) as! CategoryDefaultTableViewCell 
    cell.titleTextView.text = data[indexPath.section][indexPath.row] 
    return cell 
} 

override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { 
    return "Section \(section)" 
} 

screenshot

+1

* titleFor **页脚** InSection *与* titleFor **标题** InSection * – vadian

+0

谢谢@vadian – ericknmp

回答

0

这是因为你使用的是错误的回调。

使用override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?而不是override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?

前者将文本作为标题置于该部分的上方。后者将其置于底部。

+0

我怎么能看不到?谢谢 – ericknmp