背景为什么它需要的tableView(_:indentationLevelForRowAt :)插入细胞与细胞的静态表视图
的故事来自于书IOS学徒(埃德的第二个例子,当6 2016 )
创建了一个带有两节的UItableView。在故事板中设计了以下内容:第0节有一行满足一个静态单元格,第1节有两行满满两个静态单元格。
怎么实现
当接头区段1的最后一行(即,在画面A的的dueDate列)用的UIDatePicker一个新的细胞会被插入的tableView(请参阅画面B )
如何笔者解决充满的UIDatePicker问题
一个UITableViewCell中加入现场对接在storyBoard中(请参阅图C),当dueDate行被挖掘时,新的tableCell将被添加到表中
静态单元格的表视图没有数据源,因此不使用像“cellForRowAt” 。为了这个单元格中插入到表中的以下数据源的功能已经覆盖
tableView(_:numberOfRowsInSection:)
tableView(_:cellForRowAt:)
tableView(_:heightForRowAt:)
tableView(_:indentationLevelForRowAt:)
问题
功能tableView(_:indentationLevelForRowAt:)
真正混淆了我很多!这里是完整的代码
override func tableView(_ tableView: UITableView, indentationLevelForRowAt indexPath: IndexPath) -> Int {
var newIndexPath = indexPath
if indexPath.section == 1 && indexPath.row == 2 {
newIndexPath = IndexPath(row: 0, section: indexPath.section)
}
return super.tableView(tableView, indentationLevelForRowAt: newIndexPath)
}
问题
这是什么功能的含义是什么?它的目的是什么?我已阅读document,但我没有得到太多的信息。
当插入第三行/ datePicker单元(indexPath.section == 1 && indexPath.row == 2)
为什么函数会缩进第一行newIndexPath = IndexPath(row: 0, section: indexPath.section)
?
很好的答案!非常感谢。 – SLN