在UITableView中实现页脚的正确方法 [英] Proper way to implement a footer in UITableView

查看:53
本文介绍了在UITableView中实现页脚的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在 此处 ,我只需将UITableViewCell拖到情节提要中的UITableViewController的底部,然后将其用作页脚即可.此页脚行中有一个活动指示器.它的宽度为320,高度为55,指示器在行中居中.请注意,它是一个 UIView ,而不是UITableViewCell,因为我只能使其与前者一起使用.

So I read here that I can simply drag a UITableViewCell to the bottom of my UITableViewController in storyboard and have it act like a footer. This footer row has an activity indicator in it that's it. It's width is 320 and height 55 with the indicator centered in the row. Note that it's a UIView rather than a UITableViewCell because I can only get it to work with the former.

首先,UITableView不会在页脚处停下来.如果页脚将滚动范围扩展到UITableView的底部之外,则可以看到该页脚.一旦用户松开手指,UITableView将其滚动返回到最后一个元素,则页脚将从站点中消失.我正在尝试执行Instagram正在执行的操作-如果滚动到底部,您可以在底部看到其自定义活动指示器,而UITable将在该指示器处保持其滚动位置.我怎样才能做到这一点?

First, The UITableView doesn't stop at the footer. One can see the footer if he extends his scrolling beyond the bottom of the UITableView. As soon as the user releases his finger, the footer disappears from site as the UITableView returns its scrolling back to the last element. I am trying to do what Instagram is doing - if you scroll to the bottom you can see their custom activity indicator at the bottom and the UITable will remain its scrolling position at that indicator. How can I achieve this?

第二,我通过某些用户操作执行了一些自定义滚动.现在,我有以下代码:

Second, I have some custom scrolling performed by certain user actions. Right now, I have the following code:

    if (row + 1 < [self.tableView numberOfRowsInSection:0]) { 
        [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:row+1 inSection:0]
                              atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
    } else {
        // TODO scroll a little down so the user can see the activityIndicator
    }

如何告诉我的tableView以编程方式滚动到页脚并将其停在那里?

How can I tell my tableView to scroll programmatically to the footer and have it stop there?

第三从一开始,我的UITableView必须先从服务器中获取内容,然后才能填充tableView.不幸的是,我无法获得页脚视图来最大化UITableView的空间,从而使activityIndi​​cator出现在中间.现在,它是这样的:

Third During the very beginning, my UITableView has to fetch things from my server before it can populate the tableView. Unfortunately i can't get the footer view to maximize the space of the UITableView so that the activityIndicator will appear in the center. Right now this is how it looks:

我认为我已经正确设置了结构:

I think I have the structs set correctly:

我怀疑在UITableView中包含UIView可能会阻止视图最大化.

I suspect that having a UIView within a UITableView might prevent the view from maximizing.

摘要关于以上问题有什么建议吗?对于这个问题的冗长,我深表歉意,但我认为它们都与上述同一问题有关.

Summary Any recommendations on the above issues? I apologize for the length of this question, but I feel that they are all related to the same problem mentioned above.

推荐答案

我终于知道了.

关于@zing和@Lithu的答案,这很有用.但是,从此方法返回一个footerView会强制footerView粘贴"到TableView的底部.我的意思是,始终会显示footerview(这不是我想要的东西)

With regards to @zing and @Lithu answers, that worked. However, returning a footerView from this method forces the footerView to "stick" to the bottom of the TableView. By this I mean that the footerview will always be shown (which is not something I want)

我最终使用了self.tableView.footerView = MyView.我禁用了UIView上的所有spring和struct设置,它非常适合.(我之前已将其设置为最大化,希望在表中没有任何内容时将其最大化)

I finally used self.tableView.footerView = MyView. I disabled ALL the spring and struct settings on my UIView and it fits perfectly. (I've previously set it to maximize hoping to have it maximize when there is nothing in the table)

关于活动指示器的居中:我最终将如果UITableView中没有任何内容,则将页脚视图设置为隐藏(通过检入numberOfRows).如果发生这种情况,我会以编程方式在中间添加ActivityIndi​​cator.

Regarding centering the activity indicator: I ended up setting the footer view to hidden if there's nothing in the UITableView (by checking in numberOfRows). I programmatically added the ActivityIndicator in the center if this occurs.

感谢所有答案!

这篇关于在UITableView中实现页脚的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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