Hello,
I want to add Sections and add rows in the last section created.
But When I add a section and after add a row it add rows for all section and I want only to the last created section.
I do this :
A action of a button to add Sections :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 @interface SectionTestViewController () { NSMutableArray *sectionsArray; NSMutableArray *rowsInSectionsArray; NSInteger currentSection; } @end @implementation SectionTestViewController - (void)viewDidLoad { [super viewDidLoad]; self.myTableView.delegate = self; self.myTableView.dataSource = self; sectionsArray = [[NSMutableArray alloc]init]; rowsInSectionsArray = [[NSMutableArray alloc]init]; currentSection = 0; } #pragma tableview delegate and datasource methods -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return sectionsArray.count; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return rowsInSectionsArray.count; } -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return [sectionsArray objectAtIndex:section]; }
A action of a button to add Row :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 - (IBAction)addSectionButton:(id)sender { [sectionsArray addObject:[NSString stringWithFormat:@"Section %lu", (unsigned long)sectionsArray.count]]; currentSection++; [self.myTableView reloadData]; }
Thanks for help
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 - (IBAction)addRowButton:(id)sender { [rowsInSectionsArray addObject:[NSString stringWithFormat:@"Ligne %lu", (unsigned long)rowsInSectionsArray.count]]; [self.myTableView reloadData]; }
Partager