YYRootViewController.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // YERootViewController.m
  3. // YYKitExample
  4. //
  5. // Created by ibireme on 14-10-13.
  6. // Copyright (c) 2014 ibireme. All rights reserved.
  7. //
  8. #import "YYRootViewController.h"
  9. #import "YYKit.h"
  10. @interface YYRootViewController ()
  11. @property (nonatomic, strong) NSMutableArray *titles;
  12. @property (nonatomic, strong) NSMutableArray *classNames;
  13. @end
  14. @implementation YYRootViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. self.title = @"YYKit Example";
  18. self.titles = @[].mutableCopy;
  19. self.classNames = @[].mutableCopy;
  20. [self addCell:@"Model" class:@"YYModelExample"];
  21. [self addCell:@"Image" class:@"YYImageExample"];
  22. [self addCell:@"Text" class:@"YYTextExample"];
  23. // [self addCell:@"Utility" class:@"YYUtilityExample"];
  24. [self addCell:@"Feed List Demo" class:@"YYFeedListExample"];
  25. [self.tableView reloadData];
  26. //[self log];
  27. }
  28. - (void)log {
  29. printf("all:%.2f MB used:%.2f MB free:%.2f MB active:%.2f MB inactive:%.2f MB wird:%.2f MB purgable:%.2f MB\n",
  30. [UIDevice currentDevice].memoryTotal / 1024.0 / 1024.0,
  31. [UIDevice currentDevice].memoryUsed / 1024.0 / 1024.0,
  32. [UIDevice currentDevice].memoryFree / 1024.0 / 1024.0,
  33. [UIDevice currentDevice].memoryActive / 1024.0 / 1024.0,
  34. [UIDevice currentDevice].memoryInactive / 1024.0 / 1024.0,
  35. [UIDevice currentDevice].memoryWired / 1024.0 / 1024.0,
  36. [UIDevice currentDevice].memoryPurgable / 1024.0 / 1024.0);
  37. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  38. [self log];
  39. });
  40. }
  41. - (void)addCell:(NSString *)title class:(NSString *)className {
  42. [self.titles addObject:title];
  43. [self.classNames addObject:className];
  44. }
  45. #pragma mark - Table view data source
  46. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  47. return _titles.count;
  48. }
  49. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  50. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YY"];
  51. if (!cell) {
  52. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YY"];
  53. }
  54. cell.textLabel.text = _titles[indexPath.row];
  55. return cell;
  56. }
  57. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  58. NSString *className = self.classNames[indexPath.row];
  59. Class class = NSClassFromString(className);
  60. if (class) {
  61. UIViewController *ctrl = class.new;
  62. ctrl.title = _titles[indexPath.row];
  63. [self.navigationController pushViewController:ctrl animated:YES];
  64. }
  65. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  66. }
  67. @end