YYImageExample.m 2.0 KB

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