YYImageExample.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // YYImageExample.m
  3. // YYKitExample
  4. //
  5. // Created by ibireme on 15/7/18.
  6. // Copyright (c) 2015 ibireme. All rights reserved.
  7. //
  8. #import "YYImageExample.h"
  9. #import "YYKit.h"
  10. #import <ImageIO/ImageIO.h>
  11. #import <WebP/demux.h>
  12. @interface YYImageExample()
  13. @property (nonatomic, strong) NSMutableArray *titles;
  14. @property (nonatomic, strong) NSMutableArray *classNames;
  15. @end
  16. @implementation YYImageExample
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.titles = @[].mutableCopy;
  20. self.classNames = @[].mutableCopy;
  21. [self addCell:@"Animated Image" class:@"YYImageDisplayExample"];
  22. [self addCell:@"Progressive Image" class:@"YYImageProgressiveExample"];
  23. [self addCell:@"Web Image" class:@"YYWebImageExample"];
  24. //[self addCell:@"Benchmark" class:@"YYImageBenchmark"];
  25. [self.tableView reloadData];
  26. }
  27. - (void)addCell:(NSString *)title class:(NSString *)className {
  28. [self.titles addObject:title];
  29. [self.classNames addObject:className];
  30. }
  31. #pragma mark - Table view data source
  32. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  33. return _titles.count;
  34. }
  35. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  36. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YY"];
  37. if (!cell) {
  38. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YY"];
  39. }
  40. cell.textLabel.text = _titles[indexPath.row];
  41. return cell;
  42. }
  43. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  44. NSString *className = self.classNames[indexPath.row];
  45. Class class = NSClassFromString(className);
  46. if (class) {
  47. UIViewController *ctrl = class.new;
  48. ctrl.title = _titles[indexPath.row];
  49. [self.navigationController pushViewController:ctrl animated:YES];
  50. }
  51. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  52. }
  53. @end