YYUtilityExample.m 1.7 KB

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