iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4910字,纯文字阅读大概需要8分钟。
内容图文
首先我们先明确一下问题:
//
// PIcTableViewController.h
// 故事版自定义Cell 内加线程
//
// Created by tareba on 15/12/2.
// Copyright ? 2015年 tanada. All rights reserved.
//
#import
@interface PIcTableViewController : UITableViewController
@end
//
// PIcTableViewController.m
// 故事版自定义Cell 内加线程
//
// Created by tareba on 15/12/2.
// Copyright ? 2015年 tanada. All rights reserved.
//
//#import "AppRecord.h"
#import "PIcTableViewController.h"
#import "NewCell.h"
@interface PIcTableViewController ()
@property (nonatomic,strong) NSMutableArray * arrIamge;
@property(nonatomic,strong) NSOperationQueue *operationQueue;
@property (nonatomic,strong)NSArray*imgURLs;
@property (nonatomic,strong)UIImage *image;
@end
@implementation PIcTableViewController
- (NSArray *)imgURLs {
if(_imgURLs == nil) {
NSString*i1=@"http://down.tutu001.com/d/file/20101129/2f5ca0f1c9b6d02ea87df74fcc_560.jpg";
NSString *i2=@"http://img.taopic.com/uploads/allimg/130501/240451-13050106450911.jpg";
NSString* i3=@"http://pic.nipic.com/2007-11-09/2007119122519868_2.jpg";
NSString* i4=@"http://pic.nipic.com/2007-11-09/200711912230489_2.jpg";
_imgURLs =@[[NSURL URLWithString:i1],[NSURL URLWithString:i2],[NSURL URLWithString:i3],[NSURL URLWithString:i4] ];
}
return _imgURLs;
}
-(void)downloadImage:(NSArray*)arrURLs{
for (int i=0; icount; i++) {
NSData *data=[NSData dataWithContentsOfURL:self.imgURLs[i]];
UIImage *image=[UIImage imageWithData:data];
[self.arrIamge addObject: image];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
NSInvocationOperation*op=[[NSInvocationOperation alloc]initWithTarget:self selector:@selector(downloadImage:) object:self.imgURLs];
NSOperationQueue *queue=[[NSOperationQueue alloc]init];
[queue addOperation:op];
self.tableView.backgroundColor=[UIColor whiteColor];
[self.tableView registerClass:[NewCell class] forCellReuseIdentifier:@"Cell"];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 200;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Incomplete implementation, return the number of sections
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete implementation, return the number of rows
return 12;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
if (self.arrIamge.count!=self.imgURLs.count) {
cell.imageview.image=[UIImage imageNamed:@"Lion.jpg"];
NSLog(@"%@",cell.imageview.image);
return cell;
}else{
NSInteger index=indexPath.row%self.arrIamge.count;
cell.imageview.image=self.arrIamge[index];
return cell;
}
// dispatch_async( dispatch_get_main_queue(), ^{
// cell.imageview.image=self.image;
// NSLog(@"2 %@",[NSThread currentThread]);
// });
//
}
- (NSMutableArray *) arrIamge {
if(_arrIamge == nil) {
_arrIamge = [NSMutableArray array ];
}
return _arrIamge;
}
@end
自定义的cell
//
// NewCell.h
// 故事版自定义Cell 内加线程
//
// Created by tareba on 15/12/2.
// Copyright ? 2015年 tanada. All rights reserved.
//
#import
@interface NewCell : UITableViewCell
@property (strong, nonatomic) UIImageView *imageview;
@end
//
// NewCell.m
// 故事版自定义Cell 内加线程
//
// Created by tareba on 15/12/2.
// Copyright ? 2015年 tanada. All rights reserved.
//
#import "NewCell.h"
@implementation NewCell
- (UIImageView *)imageview {
if(_imageview == nil) {
_imageview = [[UIImageView alloc] init];
_imageview.backgroundColor=[UIColor redColor];
[self.contentView addSubview:_imageview];
[_imageview mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
}];
self.contentView.contentMode=UIViewContentModeScaleAspectFit;
}
return _imageview;
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
原文:http://www.cnblogs.com/zhao-jie-li/p/5128481.html
内容总结
以上是互联网集市为您收集整理的iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见全部内容,希望文章能够帮你解决iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。