当用户到达UITableView的最后一行时,如何动态添加行? [英] How to make dynamically adding of rows when user reached to the last row of the UITableView?

查看:103
本文介绍了当用户到达UITableView的最后一行时,如何动态添加行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableview ,其中显示10行,其中固定为静态。现在我想添加一个功能。当用户到达 UITableView 的最后一行时,我想为表添加更多的10行。我的意思是我现在在应用程序中显示固定的10行。



但是,现在我想要添加10个行,每当用户到达之前的 UITableview 的最后一行。 p>

请给我任何建议或任何示例代码来实现我的动机。感谢提前。

解决方案

你真的想要调用额外的10行的加载?当用户只是向下滚动以查看默认加载的前10个,他可能不想再加载10个。



您可以添加添加更多行作为表的最后一行。当用户点击这一个时,您再添加10个。



(我不知道如何检测到弹跳效果,如将可见行移动到指示那个人想要看到更多。)



基本逻辑如下所示:


  1. cellForRowAtIndexPath 中,检查用户是否点击最后一行,然后调用您的代码将10

  2. 添加到实际上添加了10条更多的行,您必须调用 [myTable reloadData]

  3. ,但在您打电话之前,需要增加返回值 numberOfRowsInSection 10,并确保 cellForRowAtIndexPath 将正确返回您的新行11-20

如果您真的希望在用户到达表的末尾时加载10个额外的行,则需要在 cellForRowAtIndexPath 或 willDisplayCell:forRowAtIndexPath:当被调用为您的最后一行。


I have a UITableview which shows 10 rows currently which is fixed static. Now I want to add a feature into it. I want to add a more 10 rows to the table when user reach to the last row of the UITableView. I mean currently I am showing fixed 10 rows in the application.

But now I want to add 10 more rows whenever user reaches to the last row of previous UITableview.

Please give me any suggestions or any sample code to achieve my motive. Thanks in advance.

解决方案

How would you exactly want to invoke the loading of the additional 10 rows? When a user just scrolls down to see the first 10 that are loaded by default he might not want to load 10 more already.

You may add a "add more" line as the last row of your table. When the user clicks on this one you add 10 more.

(I don't know how one would detect a "bouncing effect" like shifting up the visible rows to indicate that one would like to see more.)

The basic logic would look like this:

  1. in cellForRowAtIndexPath you check if the user clicked on the last line and then invoke your code to add the 10
  2. to actually add 10 more lines you have to call [myTable reloadData]
  3. but before you call you need to increase the returned value of numberOfRowsInSection by 10 and make sure that cellForRowAtIndexPath will correctly return your new lines 11-20

ps if you REALLY want 10 additional rows to be loaded when the user reaches the end of the table you need to invoke the loading of 10 more in cellForRowAtIndexPath or willDisplayCell:forRowAtIndexPath: when it is called for your last line.

这篇关于当用户到达UITableView的最后一行时,如何动态添加行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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