如何在UITableView Swift底部插入新行

编程入门 行业动态 更新时间:2024-10-10 07:21:51
本文介绍了如何在UITableView Swift底部插入新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我用

func insertRowsAtIndexPaths(indexPaths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation)

在表中插入新行的方法.但是它显示在UITableView的顶部(默认情况下).

method to insert a new Row in a table. But it appears from Top of the UITableView (by default).

我找不到任何从表格底部插入行的选项,如屏幕截图所示:

I couldn't find any option to insert rows from the bottom of the table, like on screenshot:

我尝试使用UIEdgeInsetsMake:

self.tableView.contentInset = UIEdgeInsetsMake(tableView.frame.height,0,0,0)

但是当我滚动表格时,它破坏了所有设计.

but it broke all design when I scroll the table.

我的问题是:如何从表格底部插入新行?

My question is: how to insert a new rows from bottom of the table?

UPD::添加新行后,表格应该看起来像是从键盘视图移动到了NavigationBar.

UPD: It should looks like table moves from a keyboard View to NavigationBar when new row is added.

UPD2::这是我想要的: recordit.co/JoR7xuvvpG

我是在

self.tableView.contentInset = UIEdgeInsetsMake(tableView.frame.height,0,0,0)

但是contentInset在行上方添加了一个大白色字段,当我向下滚动时,它隐藏了添加的行.看起来它们正隐藏在keyboardView下.我想阻止它.

But contentInset adds a big white field above the rows and when I scroll down it hides added rows. Looks like they is hiding under the keyboardView. I want to prevent it.

推荐答案

感谢@raf的建议:

然后,您需要做的是在插入元素时在其父视图中为整个UITableView设置动画.如果您使用的是autolayout,请捕获属性中的Top约束,并在插入元素时将其更改为constant.像这样:

What you need to do then, is animate the whole UITableView in it's parent view up as you insert elements. If you're using autolayout, capture the Top constraint in a property, and change it's constant as you insert elements. Something like:

topConstraint.constant = newValue UIView.animateWithDuration(0.5, animations: { self.layoutIfNeeded() })

更多推荐

如何在UITableView Swift底部插入新行

本文发布于:2023-10-26 18:08:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530935.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   UITableView   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!