我有兴趣有一个表格评论(类似于instagram评论)。到目前为止,我已经使用自定义单元格为我的set数组dataName中的注释建立了一个textView。我想知道如何才能在tableview的最后一行设置一个文本框和按钮作为输入更多评论的地方。我是否需要为此创建另一个定制单元并在cellForRowAt indexPath中实现这个?Swift 3.0使用表格视图来显示和添加评论
var comments = ["I like this item","Where did you get this?", "I can't believe you found this!", "Hello", "Yay"]
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return comments.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CustomCell
cell.commentView.text = dataName[indexPath.row]
cell.commentView.textColor = UIColor.lightGray
cell.commentView.isEditable = false
cell.commentView.isScrollEnabled = false
return cell
}
@matt我只是无法理解如何添加不同类型的单元格到tableview。并且有能力说我想要特定的单元格在某一行 – Kevin
好的,这是一个很好的答案。那么,只需要两个具有两个不同标识符的单元格原型。如果您位于最后一行,请在您的“出列”调用中请求“注释”单元格原型。 – matt