SDWebImage的用法
来源:互联网 发布:淘宝上评论在哪里 编辑:程序博客网 时间:2024/05/17 09:33
#import "ViewController.h"
#import “one.h” //创建的模型、里面声明属性
#import "UIImageView+WebCache.h"
//#import "firstTableViewCell.h" // 使用xib的话引入这个创建的头文件
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UITableView *TwoTableView;
@property (nonatomic,strong) UIView *OneView;
@property (nonatomic,strong) NSMutableArray *AllDataArray;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
// 注册cell
// [self.TwoTableView registerNib:[UINib nibWithNibName:@"firstTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"]; //使用自定义的cell要注册
[self.viewaddSubview:self.OneView];
[self.viewaddSubview:self.TwoTableView];
self.TwoTableView.delegate =self;
self.TwoTableView.dataSource =self;
[selfloadData];
}
#pragma mark 加载数据
- (void)loadData {
self.AllDataArray = [NSMutableArrayarray];
__blocktypeof(self) weakSelf =self;
// 准备网址
NSURL *url = [NSURLURLWithString:@"http://app.9nali.com/index/778?page_id=1&device=iPhone&version=1.1.2"];
// 创建请求对象
NSMutableURLRequest *request = [NSMutableURLRequestrequestWithURL:url];
// 设置请求类型
[request setHTTPMethod:@"GET"];
// 连接服务器
[NSURLConnectionsendAsynchronousRequest:request queue:[NSOperationQueuemainQueue] completionHandler:^(NSURLResponse *response,NSData *data, NSError *connectionError) {
// 判断数据是否为空,如果是的话就直接返回
if (data ==nil) {
return ;
}
// 解析
NSMutableDictionary *dict = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingAllowFragmentserror:nil];
NSArray *array = dict[@"list"];
for (NSDictionary *itemin array) {
one *l = [onenew];
[l setValuesForKeysWithDictionary:item];
[weakSelf.AllDataArrayaddObject:l];
NSLog(@"%@", weakSelf.AllDataArray[0]);
}
[self.TwoTableViewreloadData]; //刷新数据
}];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark 懒加载
- (UIView *)OneView {
if (_OneView ==nil) {
_OneView = [[UIViewalloc] initWithFrame:CGRectMake(0,0, 375,200)];
_OneView.backgroundColor = [UIColorredColor];
}
return_OneView;
}
- (UITableView *)TwoTableView {
if (_TwoTableView ==nil) {
_TwoTableView = [[UITableViewalloc] initWithFrame:CGRectMake(0,200, 375,300) style:UITableViewStyleGrouped];
}
return_TwoTableView;
}
#pragma mark 实现tabllView的代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return_AllDataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"cell"];
}
one *l =_AllDataArray[indexPath.row];
cell.textLabel.text = l.nickname;
// [cell.imageView sd_setImageWithURL:[NSURL URLWithString:l.mediumLogo] placeholderImage:[UIImage imageNamed:@"music.jpg"]];
[cell.imageViewsd_setImageWithURL:[NSURLURLWithString:l.mediumLogo]placeholderImage:[UIImageimageNamed:@"music.jpg"]completed:^(UIImage *image,NSError *error, SDImageCacheType cacheType,NSURL *imageURL) {
}];
return cell;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
- SDWebImage的用法
- SDWebImage的用法 (公司面试可能会问道)
- SDWebImage库的理解
- SDWebImage的使用
- SDWebImage的block使用
- SDWebImage图片的处理
- SDwebImage的缓存
- SDWebImage的实现原理
- SDWebImage的使用
- SDWebImage的基本使用
- SDWebImage的基本使用
- 最新版SDWebImage的使用
- 最新版SDWebImage的使用
- 最新版SDWebImage的使用
- 最新版SDWebImage的使用
- 最新版SDWebImage的使用
- 最新版SDWebImage的使用
- 最新版SDWebImage的使用
- 智能指针(smart pointer)(1):auto_ptr
- 摆脱“依赖”
- 13.过拟合
- MySQL性能优化的21条最佳经验
- C3P0的使用
- SDWebImage的用法
- error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup msvcrtd
- iPhone 二手手机到底去哪了
- 案例:修改网站标题对排名有什么影响?
- 解决Exception in thread “main" java.lang.UnsupportedClassVersionError
- mongodb update更新一条和更新多条
- 为什么你的智能硬件没有脱颖而出?看完你就懂了
- Hadoop权威指南第六章
- Java 异常处理的误区和经验总结(精)