简体   繁体   English

iPhone-将新的节和行添加到UITableView

[英]iPhone - Adding new sections and rows into UITableView

I have a UITableView to display a list of data. 我有一个UITableView来显示数据列表。

The list will contain images, so I am loading images with lazy loading. 该列表将包含图像,因此我正在使用延迟加载来加载图像。 Now I don't want to load the whole list at a time. 现在,我不想一次加载整个列表。

The loading should be like, first it should load some 10 records and when we scrolling down to the tableview , it should automatically load next 10 records as on. 加载应该是这样的,首先它应该加载大约10条记录,当我们向下滚动到tableview ,它应该自动加载接下来的10条记录。

For this I need to add rows when I am scrolling to bottom. 为此,我需要在滚动到底部时添加行。 The tableview may contain different sections. tableview可能包含不同的部分。

So how can I add new rows and new sections at the end of the tableview while scrolling down? 那么,如何在向下滚动的同时在表tableview的末尾添加新行和新节?

At

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
   {
     if (indexPath.row == [yourArray count]-1)
        {
         //start fetching the next set of data in background asynchronously and when fetching is complete use delegate methods to reload or append your current UITableView , meanwhile start a activity indicator as footer to show loading
         }
   }

this is the effective method, if you try to implement synchronously when scrolling reaches bottom, it will make your device stuck 这是有效的方法,如果您尝试在滚动到达底部时同步实现,则会使设备卡住

Look at the Apple documentation about UITableView . 查看有关UITableViewApple文档 You can use the following method to add a row : 您可以使用以下方法添加一行:

- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

Firstly, the thing you want to do is known as Lazy Loading . 首先,您想做的事情被称为“ 延迟加载”

Means your table view will load images or show data in the cells which are currently visible to user. 意味着您的表格视图将在用户当前可见的单元格中加载图像或显示数据。 So have a look at this link. 因此,请看链接。 It provides sample code that might help you. 它提供了可能对您有帮助的示例代码。

And to insert row, you can use 并插入行,您可以使用

(void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM