我有興趣有一個表格評論(類似於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