“加载更多"在UITableView中 [英] "Load More" in UITableView

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

问题描述

我正在将RSS feed加载到表格视图中.我要加载10个条目,然后在最后一个单元格中或最后一个单元格下方的某个地方说加载更多",因此,当用户单击加载更多"时,其余的RSS feed将被加载.由于RSS是从我的网站上发布的,因此我可以对其进行编程,以获取服务器端的10个或所有条目(使用查询字符串等).

I'm loading an RSS feed into a table view. I'm going to load 10 entries and then would like it say "Load More" in the last cell or somewhere below the last cell, so when the user clicks on Load More, the rest of the RSS feed gets loaded. Since the RSS comes off of my web site, I can program it to get the 10 or all entries on the server side (using a query string or something).

问题是如何呈现表格,以使最后一个单元格具有加载更多"链接,用户可以单击该链接以调用一种方法来加载其余的提要(然后,当整个提要被加载时,不再有加载更多"链接.

The question is how to render a table such that the last cell has a Load More link that the can clicked to call a method to load the rest of the feed (and then when the entire feed is loaded there is no more "Load More" link).

推荐答案

由于UITableView的工作方式(即:他们根据需要请求单元格/单元格内容),加载更多"链接的含义是什么?(尤其是您可能需要完全加载RSS feed.)

Due to the way that UITableView's work (i.e.: they request cells/cell content as required) what's the value in the 'load more' link? (Especially as you'll presumably need to load the RSS feed in its entirely anyway.)

换句话说,用户滚动表格视图的行为不应该足够吗?

In other words, shouldn't the act of the user scrolling the table view be sufficient?

从用户界面的角度来看,这也可能会让人感到困惑-底部是否会加载更多"加载较旧的帖子或较新的帖子?这些帖子会出现在哪里?在视图的顶部还是底部?(我假设您要按照最新的优先"顺序对单元格进行排序,因为如果您正在使用Feed,这可能是有道理的.)

It's also potentially a bit confusing from a User Interface perspective - would having a "load more" at the bottom load older posts or newer posts? Where would these posts appear? At the top of the view or the bottom? (I'm presuming that you're ordering the cells in "most recent first" order, as this probably makes sense if you're consuming a feed.)

更新

但是,如果您真的想这样做,我建议您首先使您的数据源仅告诉UITableView它具有"n"个+1元素,而+1是包含以下内容的单元格您的加载更多"文字.(您可以使用

However, if you really want to do this I'd suggest initially making your data source only tell the UITableView that it has "n"+1 elements, the +1 being a cell that contains your "load more" text. (You could format the cell to look different, using the backgroundView method, etc. on the UITableViewCell you supply.)

当用户选择此最后一个单元格时,您需要照常捕获它,确定它是否是假的加载更多"单元格,如果是,请告知数据源应将其所有内容公开给UITableView.然后,您可以简单地获取表视图以重新加载自身(通过reloadData方法),一切都应该很好.

When the user selects this final cell you'll need to capture this as per usual, work out if it's the fake "load more" cell and if so, tell the data source that it should reveal all of its contents to the UITableView. Then you can simply get the table view to reload itself (via the reloadData method) and all should be well.

这篇关于“加载更多"在UITableView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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