completionHandler) { |
_completionHandler(); |
} |
|
}); |
|
}); |
} |
|
} |
#pragma mark - 加载本地图像 |
- (UIImage *)loadLocalImage:(NSString *)imageUrl |
{ |
self.imageUrl = imageUrl; |
// 获取图像路径 |
NSString * filePath = [self imageFilePath:self.imageUrl]; |
UIImage * image = [UIImage imageWithContentsOfFile:filePath]; |
if (image != nil) { |
return image; |
} |
return nil; |
} |
#pragma mark - 获取图像路径 |
- (NSString *)imageFilePath:(NSString *)imageUrl |
{ |
// 获取caches文件夹路径 |
NSString * cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; |
// 创建DownloadImages文件夹 |
NSString * downloadImagesPath = [cachesPath stringByAppendingPathComponent:@"DownloadImages"]; |
NSFileManager * fileManager = [NSFileManager defaultManager]; |
if (![fileManager fileExistsAtPath:downloadImagesPath]) { |
[fileManager createDirectoryAtPath:downloadImagesPath withIntermediateDirectories:YES attributes:nil error:nil]; |
} |
#pragma mark 拼接图像文件在沙盒中的路径,因为图像URL有"/",要在存入前替换掉,随意用"_"代替 |
NSString * imageName = [imageUrl stringByReplacingOccurrencesOfString:@"/" withString:@"_"]; |
NSString * imageFilePath = [downloadImagesPath stringByAppendingPathComponent:imageName]; |
return imageFilePath; |
} |
@end</foundation> |
@这里只给出关键代码,网络请求,数据处理,自定义cell自行解决 |
#pragma mark - Table view data source |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView |
{ |
// Return the number of sections. |
return 1; |
} |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section |
{ |
// Return the number of rows in the section. |
if (_dataArray.count == 0) { |
return 10; |
} |
return [_dataArray count]; |
} |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath |
{ |