-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeViewController.m
More file actions
111 lines (101 loc) · 3.84 KB
/
Copy pathHomeViewController.m
File metadata and controls
111 lines (101 loc) · 3.84 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// HomeViewController.m
// CCKit
//
// Created by CC on 2020/1/16.
// Copyright © 2020 CC. All rights reserved.
//
#import "HomeViewController.h"
#import "HomeDataSource.h"
#import "BubbleSort.h"
#import "SelectSort.h"
#import "MergeSort.h"
#import "QuickSort.h"
#import "ShellSort.h"
#import "KMPSearch.h"
#import "HeapSort.h"
#import "AVLTree.h"
@interface HomeViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(strong,nonatomic)UITableView *table;
@end
@implementation HomeViewController
static NSString *cellId = @"cellID";
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.table = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
self.table.dataSource = self;
self.table.delegate = self;
[self.table registerClass:[UITableViewCell class] forCellReuseIdentifier:cellId];
[self.view addSubview:self.table];
}
#pragma mark UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [HomeDataSource shareInstance].dataSource.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *cells = [[HomeDataSource shareInstance].dataSource objectAtIndex:section][@"cells"];
return cells.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
NSDictionary *cellData = [HomeDataSource shareInstance].dataSource[indexPath.section][@"cells"][indexPath.row];
cell.textLabel.text = cellData[@"title"];
cell.textLabel.numberOfLines = 0;
return cell;
}
#pragma mark UIScrollViewDelegate
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UILabel *label = [UILabel new];
NSString *headerTitle = [HomeDataSource shareInstance].dataSource[section][@"header"];
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor grayColor];
label.text = headerTitle;
label.font = [UIFont systemFontOfSize:17];
[label sizeToFit];
return label;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.section==0){
return 60.0f;
}else {
return 44.0f;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.01f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 30.0f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSDictionary *sectiondata = [HomeDataSource shareInstance].dataSource[indexPath.section];
NSArray *cellDatas = sectiondata[@"cells"];
NSDictionary *cellData = cellDatas[indexPath.row];
NSString *title = cellData[@"title"];
NSString *header = sectiondata[@"header"];
if([header isEqualToString:@"排序"]){
if([title isEqualToString:@"冒泡排序"]){
[[BubbleSort new] test];
}else if([title isEqualToString:@"选择排序"]){
[[SelectSort new] test];
}else if([title isEqualToString:@"归并排序"]){
[[MergeSort new] test];
}else if([title isEqualToString:@"希尔排序"]){
[[ShellSort new] test];
}else if([title isEqualToString:@"快速排序"]){
[[QuickSort new] test];
}else if([title isEqualToString:@"堆排序"]){
[[HeapSort new] test];
}
}else if([header isEqualToString:@"字符串查找"]){
if([title isEqualToString:@"kmp"]){
[[KMPSearch new] test];
}
}else if([header isEqualToString:@"树"]){
if([title isEqualToString:@"AVL树"]){
[[AVLTree new] test];
}
}
}
@end