[英]How to insert a new Row in bottom of the UITableView Swift
我用
func insertRowsAtIndexPaths(indexPaths: [NSIndexPath],
withRowAnimation animation: UITableViewRowAnimation)
在表中插入新行的方法。 但它出现在UITableView
顶部(默认情况下)。
我找不到任何从表格底部插入行的选项,比如屏幕截图:
我尝试过使用UIEdgeInsetsMake
:
self.tableView.contentInset = UIEdgeInsetsMake(tableView.frame.height,0,0,0)
但是当我滚动桌子时,它打破了所有的设计。
我的问题是:如何从表格底部插入新行?
UPD:当添加新行时,它应该看起来像从键盘视图移动到NavigationBar。
UPD2:这就是我想要的: http : //recordit.co/JoR7xuvvpG
我是在帮助下做到的
self.tableView.contentInset = UIEdgeInsetsMake(tableView.frame.height,0,0,0)
但是contentInset在行上方添加了一个大的白色字段,当我向下滚动时,隐藏了添加的行。 看起来他们藏在keyboardView下面。 我想阻止它。
斯威夫特3
TableView.beginUpdates()
let indexPath:IndexPath = IndexPath(row:(self.yourArray.count - 1), section:0)
TableView.insertRows(at: [indexPath], with: .left)
TableView.endUpdates()
TableView.scrollToRow(at: indexPath, at: .bottom, animated: true)
func insertRowsAtIndexPaths(indexPaths: [NSIndexPath],
withRowAnimation animation: UITableViewRowAnimation)
这是附加行的方法。 要在底部插入行,您需要提供最后一行的索引路径。
例如:
var IndexPathOfLastRow = NSIndexPath(forRow: self.array.count - 1, inSection: 0)
self.tableView.insertRowsAtIndexPaths([IndexPathOfLastRow], withRowAnimation: UITableViewRowAnimation.Left)
您是否尝试使用UITableViewRowAnimationBottom
作为行动画参数?
像这样:(在swift中)
tableView.insertRowsAtIndexPaths([indexPath],
withRowAnimation: UITableViewRowAnimation.Bottom)
或Objective-C:
[self insertRowsAtIndexPaths:indexPaths
withRowAnimation:UITableViewRowAnimationBottom];
感谢@raf的建议:
您需要做的是,在插入元素时,在其父视图中为整个UITableView
设置动画。 如果您正在使用autolayout
,请捕获属性中的Top约束,并在插入元素时更改它的constant
。 就像是:
topConstraint.constant = newValue
UIView.animateWithDuration(0.5, animations: {
self.layoutIfNeeded()
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.