[Swift]tableView插入对话内容

今天总结下插入对话内容的基本实现方式。一般SNS类APP的对话内容都用TableView显示,我们输入内容点击发送就会插入一条信息。那么是如何实现的呢?

创建TableView和cell和xib的步骤省略了。直接看插入代码

@IBAction func addClicked(sender: AnyObject) {
        arr.append("hi")
        _tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: arr.count-1,inSection: 0)], withRowAnimation: UITableViewRowAnimation.Fade)
    }

 其中insertRowsAtIndexPaths方法用来插入新的信息。forRow参数表示插入第几行,inSection参数表示插入第几个section,后面是插入动画(没看出区别。。。)

原文地址:https://www.cnblogs.com/ybw123321/p/5537251.html