简体   繁体   English

UITableview Delegate方法在json方法之前调用

[英]UITableview Delegate method calls before json method

In my project I use NSJSONSerialization 在我的项目中,我使用NSJSONSerialization

dispatch_async(kBgQueue, ^{

    NSData* data = [NSData dataWithContentsOfURL:kLatestKivaLoansURL];

    [self performSelectorOnMainThread:@selector(fetchedData:)
                           withObject:data waitUntilDone:YES];

});

written in viewDidLoad . viewDidLoad编写。 Then I have implemented fetchedData: . 然后,我实现了fetchedData:

Problem is that I have used UITableView to display the array data from the JSON a nd before fetchedData: is called the tableview's numberOfRowsInSection: is called. 问题是我已经使用UITableView从JSON显示数组数据,并且在fetchedData:之前调用了tableview的numberOfRowsInSection: fetchedData:

I write there [myarray count]; 我在那里写[myarray count]; so it returns 0, because it calls before fetchdata. 因此它返回0,因为它在fetchdata之前调用。 Any 任何

Solution ?? 解决方案

You just need to call reloadData on the table view after you have stored the updated data. 存储更新后的数据后,只需在表视图上调用reloadData It's fine that the table view loads before then (though you may want to add a progress indicator to let the user know what's happening). 可以在此之前加载表视图,这很好(尽管您可能希望添加进度指示器以使用户知道正在发生的事情)。

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

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