化妆品网站素材,沈阳网站排名seo,佛山专业的网页制作,荆门网站建设电话咨询2019独角兽企业重金招聘Python工程师标准 昨晚第一次做用网络接口获取的数据#xff0c;显示到自己的cell上#xff0c;犯了很多的错#xff0c; 总结如下#xff1b; 1.数据源数组必须首先初始化#xff0c;一般使用的是懒加载#xff1b; 2.异步获取网络… 2019独角兽企业重金招聘Python工程师标准 昨晚第一次做用网络接口获取的数据显示到自己的cell上犯了很多的错 总结如下 1.数据源数组必须首先初始化一般使用的是懒加载 2.异步获取网络图片,通过第三方SDWebImage来做 a.首先导入这个包的 #import UIImageViewWebCache.h b.通过这个类的方法设置imageview的图片 //显示网上的图片 //参数1:需要显示的网络图片的url //参数2:占位图片(网络图片还没有下载完之前,imageView上显示的图片) //sd_setImageWithURL:placeholderImage: [_coverImageView sd_setImageWithURL:[NSURL URLWithString:model.imagePath] placeholderImage:[UIImage imageNamed: ]]; 注意:如果网络图片过大显示的时候会出现花屏的现象; 3.同步从网络获取的图片是一个URL:比如:http:www.bai.com/xxx.jpg这样子的 在显示在我们的界面上的时候代码要这样写: //从网络获取图片要用二进制得到url; NSURL *url [NSURL URLWithString:model.cover_image]; NSData *data [NSData dataWithContentsOfURL:url]; _coverImageView.image [UIImage imageWithData:data]; 2.从网络获取的数据显示在tableViewCell必须要刷新 代码如下: #pragma mark - 准备数据 - (void)prepareData{ //数组的初始化 self.dataArray [[NSMutableArray alloc]init]; NSURLSessionConfiguration *config [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session [NSURLSession sessionWithConfiguration:config]; NSURL *url [NSURL URLWithString:path]; NSMutableURLRequest *request [NSMutableURLRequest requestWithURL:url]; NSURLSessionDataTask *task [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSDictionary *dict [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSArray *array dict[data][list]; for (NSDictionary *dict in array) { DataModel *myModel [[DataModel alloc] initWithDictionary:dict]; [self.dataArray addObject:myModel]; } //数据刷新 [_tableView reloadData]; }]; [task resume]; } 以上就是在从网络获取数据时候容易犯错的地方 转载于:https://my.oschina.net/luhoney/blog/667561