// // YYUtilityExample.m // YYKitDemo // // Created by ibireme on 16/2/24. // Copyright 2016 ibireme. All rights reserved. // #import "YYUtilityExample.h" #import "YYKit.h" @interface YYUtilityExample() @property (nonatomic, strong) NSMutableArray *titles; @property (nonatomic, strong) NSMutableArray *classNames; @end @implementation YYUtilityExample - (void)viewDidLoad { [super viewDidLoad]; self.titles = @[].mutableCopy; self.classNames = @[].mutableCopy; [self addCell:@"Keychain" class:@"YYKeychainExample"]; [self.tableView reloadData]; } - (void)addCell:(NSString *)title class:(NSString *)className { [self.titles addObject:title]; [self.classNames addObject:className]; } #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _titles.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YY"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YY"]; } cell.textLabel.text = _titles[indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *className = self.classNames[indexPath.row]; Class class = NSClassFromString(className); if (class) { UIViewController *ctrl = class.new; ctrl.title = _titles[indexPath.row]; [self.navigationController pushViewController:ctrl animated:YES]; } [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; } @end