NSURLConnection和UITableView的delegate执行先后问题的解决方法

来源:互联网 发布:top域名能备案吗 编辑:程序博客网 时间:2024/05/20 23:07

参考:http://stackoverflow.com/questions/12778213/uitableview-delegate-fires-nsurlconnection-delegate

一个ViewController同时包含NSURLConnection和UITableView的delegate时,无论怎样都会优先执行UITableView的delegate这就会导致dataSource出问题,那么解决方案就是:

didRecieveData might be called more than once, and does not indicates that all data is fetched. You should implement a private property on your class such as;

@property (nonatomic,retain) NSMutableData tableData;

and on your didRecieveData;

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{   [self.tableData appendData:data];}

After that when your connection is closed

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{    // use tableData and refresh table...    [self.tableView reloadData];}


NSURLConnection: http://blog.csdn.net/crycheng/article/details/21826495

0 0
原创粉丝点击