Commit 923037f7c9211773fbea1de65f07587ddd164a51

Authored by 雷浩杰
1 parent 8cf651b8

tableview test

Showing 1 changed file with 47 additions and 5 deletions
WSWebImageDemo/ViewController.m
... ... @@ -11,7 +11,10 @@
11 11 #import "CNLiveImageCache.h"
12 12 #import "UIImageView+CNLiveWebCache.h"
13 13  
14   -@interface ViewController ()
  14 +@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
  15 +{
  16 + NSArray *_imageArray;
  17 +}
15 18  
16 19 @property (nonatomic, strong) UIImageView *imageView;
17 20  
... ... @@ -45,12 +48,51 @@ static NSString *str = @&quot;http://desk.fd.zol-img.com.cn/t_s2560x1600c5/g5/M00/0D/
45 48 // NSLog(@"Do something");
46 49 // }];
47 50  
48   - UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 200)];
49   - imageView.backgroundColor = [UIColor cyanColor];
50   - [self.view addSubview:imageView];
  51 +// UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 200)];
  52 +// imageView.backgroundColor = [UIColor cyanColor];
  53 +// [self.view addSubview:imageView];
51 54  
52 55 // [imageView ws_setImageWithUrl:[NSURL URLWithString:str]];
53   - [imageView ws_setImageWithUrl:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"text.jpg"]];
  56 +// [imageView ws_setImageWithUrl:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"text.jpg"]];
  57 +
  58 + _imageArray = @[@"http://y1.cnliveimg.com:8080/image/itv/2016/0729/392ab54d87a049b6b7f7cf6d7df252d5_138931_101.jpg",
  59 + @"http://y3.cnliveimg.com:8080/image/itv/2016/0729/d56e527238a04a6d909cf080092c3e74_138923_100.jpg",
  60 + @"http://y2.cnliveimg.com:8080/image/itv/2016/0729/098609b945fc43169bea7a6093fe449e_138914_100.jpg",
  61 + @"http://y3.cnliveimg.com:8080/image/itv/2016/0729/e67a4abf5781407195e6544a1931913c_138913_100.jpg",
  62 + @"http://y3.cnliveimg.com:8080/image/itv/2016/0728/912ab18337e642439cfbca32ae527f23_138727_100.jpg",
  63 + @"http://y1.cnliveimg.com:8080/image/itv/2016/0722/75be21e738a945e3b6b0437a01437beb_101.jpg",
  64 + @"http://y1.cnliveimg.com:8080/image/itv/2016/0520/c4a9729f38f344f599be183bfb0ed0d0_100.jpg",
  65 + @"http://y1.cnliveimg.com:8080/image/itv/2016/0429/2237884c0dc64c1bbf486b7c00888cb0_119818_100.jpg",
  66 + @"http://y3.cnliveimg.com:8080/image/itv/2016/0405/f7e64bc903884ae3bebbd7493c81759e_115166_100.jpg",
  67 + @"http://y1.cnliveimg.com:8080/image/itv/2016/0116/7521576fd18f4bfbaee9efa8d379eee0_101710_100.jpg"];
  68 +
  69 + UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(100, 200, 100, 300) style:UITableViewStylePlain];
  70 + [self.view addSubview:tableView];
  71 + tableView.rowHeight = 100;
  72 + tableView.delegate = self;
  73 + tableView.dataSource = self;
  74 +
  75 +}
  76 +
  77 +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  78 +{
  79 + return _imageArray.count;
  80 +}
  81 +
  82 +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  83 +{
  84 + static NSString *identify = @"cell";
  85 + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
  86 + if (!cell) {
  87 + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
  88 + UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
  89 + [cell.contentView addSubview:image];
  90 + image.tag = 1001;
  91 + }
  92 + UIImageView *imageView = (UIImageView *)[cell viewWithTag:1001];
  93 + [imageView ws_setImageWithUrl:[NSURL URLWithString:_imageArray[indexPath.row]] placeholderImage:[UIImage imageNamed:@"text.jpg"]];
  94 +
  95 + return cell;
54 96 }
55 97  
56 98 - (void)didReceiveMemoryWarning {
... ...