ios - Swift 3.0 使用表格 View 显示和添加评论

标签 ios swift tableview custom-cell

我有兴趣拥有一个用于评论的表格 View (类似于 instagram 评论)。到目前为止,我已经使用自定义单元格为我的集合数组 dataName 中的注释设置了一个 textView。我想知道如何在 tableview 的最后一行设置一个文本字段和按钮,作为输入更多评论的地方。我是否需要为此创建另一个自定义单元格并在 cellForRowAt indexPath 中实现它?

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
}

最佳答案

您可以通过添加一个包含文本字段和按钮的 View 作为 TableView 的页脚 View 来实现您想要的效果。当添加新评论时,您将继续将评论添加到数组,并使用动画重新加载 tableview 或 insertRow。

关于ios - Swift 3.0 使用表格 View 显示和添加评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45725621/

相关文章:

iOS 11 float TableView 标题

ios - 复制 NSDictionary 到 NSMutableDictionary

ios - 使用各种控件(按钮、开关和文本字段)在 TableView 中实现上一个/下一个按钮

ios - 将信息从 TableViewController 传递到 DetailViewController

ios - 类型 'Reactive<UITextField>' 的值没有成员 'text'

ios - 有没有办法使用 Foursquare API 按价格搜索 field ?

swift - TableViewCell.xib 没有出现在 tableview 上

javascript - Android 和 iPhone 拖动(touchmove、sweep)

ios - 为 iOS 和 watchOS 创建框架目标

ios - Firebase 身份验证未被调用并返回空用户(Swift)