以下是这个.m文件的代码 就大神秒解#import "ViewController.h"
#import "MJRefresh.h"
#import "NetManager.h"
#import "UIImageView+WebCache.h"
#import "ToolsCell.h"
@interface ViewController ()
@property (nonatomic)NSArray* allTools;
@end@implementation ViewController- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[ToolsCell class] forCellReuseIdentifier:@"Cell"];
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
[NetManager getToolsListCompletionHandler:^(NSArray *dataList, NSError *error) {
self.allTools = dataList;
NSLog(@"%@",self.allTools);
[self.tableView reloadData];
[self.tableView.mj_header endRefreshing];
}];
}];
[self.tableView.mj_header beginRefreshing];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _allTools.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 60;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ToolsCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.accessoryType = 1;
ToolsDic* tool = _allTools[indexPath.row];
cell.textLabel.text = tool.name;
[[NSOperationQueue new] addOperationWithBlock:^{
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:tool.name]];
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:tool.icon] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
cell.imageView.image = image;
}];
}];
}];
return cell;
}
- (void)viewWillAppear:(BOOL)animated{
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}@end
#import "MJRefresh.h"
#import "NetManager.h"
#import "UIImageView+WebCache.h"
#import "ToolsCell.h"
@interface ViewController ()
@property (nonatomic)NSArray* allTools;
@end@implementation ViewController- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[ToolsCell class] forCellReuseIdentifier:@"Cell"];
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
[NetManager getToolsListCompletionHandler:^(NSArray *dataList, NSError *error) {
self.allTools = dataList;
NSLog(@"%@",self.allTools);
[self.tableView reloadData];
[self.tableView.mj_header endRefreshing];
}];
}];
[self.tableView.mj_header beginRefreshing];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _allTools.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 60;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ToolsCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.accessoryType = 1;
ToolsDic* tool = _allTools[indexPath.row];
cell.textLabel.text = tool.name;
[[NSOperationQueue new] addOperationWithBlock:^{
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:tool.name]];
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:tool.icon] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
cell.imageView.image = image;
}];
}];
}];
return cell;
}
- (void)viewWillAppear:(BOOL)animated{
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}@end
NSOperationQueue 不操作UI的东西的
cell.imageView.image = image;
});