繁体   English   中英

批量获取数据并将其存储在NSMutableArray中以在iPhone的UITableView中显示

[英]Get data in batches & store it in NSMutableArray to display it in UITableView in iphone

我如何一次从地址簿中批量获取说20条记录的数据,并在表格视图中显示20条记录。 当获取新的20条记录时,我想将其添加到现有数组中并重新加载数据。 我怎样才能做到这一点? 谢谢

在您要设置行的以下委托中,增加一行

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return yourMutableArray.count+1;
}

以下委托告诉您当前正在创建哪个单元格。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

在此情况下,您可以添加检查条件,例如

if(indexPath.row > yourMutableArray.count)
{

  // This means you are at the end of your table
  // Call your webservice here and append the next set of data into the yourMutableArray
  // You can also show an activity indicator over the extra cell here, Indicating the loading of new data
   [self performSelector:@selector(getDataFromWebservice) withObject:nil afterDelay:1.0];
}
else
{
  // Do your cell settings here
}

在您要检查网络服务是否成功的代码中的某处,添加以下行以重新加载表

[yourTable reloadData];

确保将新数据追加到MutableArray中,否则表将仅显示来自Web服务的最新数据。 希望这个能对您有所帮助。

暂无
暂无

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

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