设为首页 加入收藏

TOP

TableView 的优化(三)
2017-10-13 10:24:23 】 浏览:767
Tags:TableView 优化
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

{

首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇多控制器之间的跳转 下一篇代理设计模式以及书写规范

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目