This repository was archived by the owner on Jul 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYYRootViewController.m
More file actions
72 lines (58 loc) · 2.2 KB
/
YYRootViewController.m
File metadata and controls
72 lines (58 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// YYRootViewController.m
// YYKitSample
//
// Created by lichuanjun on 2017/10/11.
// Copyright © 2017年 lichuanjun. All rights reserved.
//
#import "YYRootViewController.h"
@interface YYRootViewController ()
@property (nonatomic, strong) NSMutableArray *titles;
@property (nonatomic, strong) NSMutableArray *classNames;
@end
@implementation YYRootViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"YYKit Example";
self.titles = @[].mutableCopy;
self.classNames = @[].mutableCopy;
[self addCell:@"YYCache" class:@"YYCacheExample"];
[self addCell:@"YYModel" class:@"YYModelExample"];
[self addCell:@"YYText" class:@"YYTextExample"];
// [self addCell:@"Image" class:@"YYImageExample"];
// [self addCell:@"Text" class:@"YYTextExample"];
// [self addCell:@"Utility" class:@"YYUtilityExample"];
// [self addCell:@"Feed List Demo" class:@"YYFeedListExample"];
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (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