[英]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.