1 //
2 // ViewController.h
3 // TableView
4 //
5 // Created by wky on 11/10/2017.
6 // Copyright © 2017 vector. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10
11 @interface ViewController : UIViewController
12 <UITableViewDelegate,UITableViewDataSource>
13 {
14 UITableView* _tableView;
15 NSMutableArray* _arrayData;
16 }
17
18
19 @end
1 //
2 // ViewController.m
3 // TableView
4 //
5 // Created by wky on 11/10/2017.
6 // Copyright © 2017 vector. All rights reserved.
7 //
8
9 #import "ViewController.h"
10
11 @interface ViewController ()
12
13 @end
14
15 @implementation ViewController
16
17 - (void)viewDidLoad {
18 [super viewDidLoad];
19 // Do any additional setup after loading the view, typically from a nib.
20
21
22 _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
23
24 _tableView.delegate = self;
25
26 _tableView.dataSource = self;
27
28 [self.view addSubview:_tableView];
29
30 _arrayData = [[NSMutableArray alloc]init];
31
32 for(int i='A';i<'Z';i++)
33 {
34 NSMutableArray* arraySmall = [[NSMutableArray alloc]init];
35 for(int j=1;j<6;j++)
36 {
37 NSString* str = [NSString stringWithFormat:@"%c%d",i,j];
38
39 [arraySmall addObject:str];
40
41 }
42 [_arrayData addObject:arraySmall];
43 }
44
45
46 }
47
48
49
50 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
51 {
52 NSInteger row = [[_arrayData objectAtIndex:section] count];
53
54 return row;
55 }
56
57 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
58 {
59 return _arrayData.count;
60 }
61
62
63 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
64 {
65 NSString* cellStr=@"cell";
66
67 UITableViewCell* cell = [_tableView dequeueReusableCellWithIdentifier:cellStr];
68 if(cell == nil)
69 {
70 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellStr];
71 }
72
73 cell.textLabel.text = _arrayData[indexPath.section][indexPath.row];
74
75 return cell;
76 }
77
78
79 - (void)didReceiveMemoryWarning {
80 [super didReceiveMemoryWarning];
81 // Dispose of any resources that can be recreated.
82 }
83
84
85 @end