How to make dynamically adding of rows when user reached to the last row of the UITableView?

后端 未结 4 871
夕颜
夕颜 2021-02-02 04:19

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 r

4条回答
  •  无人及你
    2021-02-02 04:57

    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.

提交回复
热议问题