如何将 UITableViewCell 定位到 TableView 的底部? [英] How to position UITableViewCell to the bottom of TableView?

查看:40
本文介绍了如何将 UITableViewCell 定位到 TableView 的底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 UITableView 中从下到上对 UITableViewCell 进行排序.有没有办法在 Swift 中做到这一点?这是 Obj-C 中的另一个类似问题;

I want to sort UITableViewCell's from bottom to top in UITableView. Is there a way to do that in Swift? Here is another question like this in Obj-C;

如何将 UITableViewCell 定位在屏幕底部?

我尝试了@replman 的回答,但效果不佳.

I tried the @replman's answer but it didn't work well.

无论如何,我想我应该解释得更详细一些.假设我们有一个 UITableView 有 1 个单元格.当我们运行时,单元格显示在屏幕底部.当我们添加第二个单元格时,第二个单元格在 tableView 的底部向上滑动,第一个单元格就在它的上方.就像 whatsapp 信使一样.

Anyway, I think I should explain more detailed. Let say we have a UITableView which has 1 cell. When we run, the cell shows up at the bottom of the screen. When we add second cell, then second cell slides up at the bottom of the tableView and first cell is just above it.Just like whatsapp messenger.

这是我从上面的问题中得到的一个很好的视觉效果.

Here is a nice visual that I took from the question above.

+----------------+     +----------------+     +----------------+
|                |     |                |     |                |
|                |     |                |     |                |
|                |     |                |     |                |
|                |     |                |     | +------------+ |
|                |     |                |     | |   cell 1   | |
|                |     |                |     | +------------+ |
|                |     | +------------+ |     | +------------+ |
|                |     | |   cell 1   | |     | |   cell 2   | |
|                |     | +------------+ |     | +------------+ |
| +------------+ |     | +------------+ |     | +------------+ |
| |   cell 1   | |     | |   cell 2   | |     | |   cell 3   | |
| +------------+ |     | +------------+ |     | +------------+ |
+----------------+     +----------------+     +----------------+

如果有人帮助我会很高兴.

I would be glad if someone help.

解决方案:

首先,翻转tableViewtableViewCell.然后反向加载单元格.它对我来说很好.有关更多信息,请查看此答案;https://stackoverflow.com/a/28435207/1404324

First, flip tableView and tableViewCell.Then load cells in reverse. It worked fine for me. For a little bit more information, check out this answer; https://stackoverflow.com/a/28435207/1404324

推荐答案

可能有很多很多方法可以实现这一点,包括:

There are probably many, many ways to achieve this, including:

  • 在第一行之前添加一行(甚至一节).将其设置为空单元格,并在添加/删除/更改行或更新布局时调整其大小

  • add a row (or even a section) before the first one. Set it to an empty cell, and adjust its size whenever you add/remove/change rows or the layout is updated

tableHeaderView 相同(您需要重新分配给 tableHeaderView 以强制 tableview 注意到大小的变化)

same thing with a tableHeaderView (you'll need to reassign to tableHeaderView to force the tableview to notice the change of size)

与节标题视图相同的内容

same thing with a section header view

同样的事情,在你的第一个单元格内有空白,在顶部

same thing with blank space inside your first cell, at the top

不要使用表格视图,而是使用您在其上添加消息的滚动视图,并以您想要的任何方式调整滚动插入/偏移

don't use a tableview but a scrollview on which you add the messages, and adjust scroll insets/offsets any way you want

当然还有更多.

这篇关于如何将 UITableViewCell 定位到 TableView 的底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆