我有一个表格View,在一开始我有一个部分和一个单元格。部分上有按钮,我可以添加更多单元格。那样就好。但在我的导航控制器栏上,我有另一个按钮项(用于添加更多部分)。部分正在添加,但每个部分中的单元格的数量保持不变。我要这个 A部分= 6个单元格 B部分= 2个细胞,依此类推。 我们可以添加更多的部分和单元格。我怎样才能反复管理每个部分的细胞数量 我的问题是我的每个部分都包含相同的单元格。
- (IBAction)addsection:(id)sender {
section +=1;
[self.tableView reloadData];
}
- (void)viewDidLoad {
[super viewDidLoad];
// sectionDictionary = @{// Section Array with its object Array Key value};
section = 1;
rowS = 1;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return section;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{ NSString *name = @"name";
return name;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return rowS;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
CreateProblemSolutionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.problemLabel.text = @"Problem";
cell.problemDetailsLabel.text = @"some problem here";
cell.solutionLabel.text = @"Solution";
cell.solutionDetails.text = @"Solution details";
return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(100.0, 0.0, 10.0, 44.0)];
[customView setBackgroundColor:[UIColor greenColor]];
UIButton *headerbutton = [[UIButton alloc]initWithFrame:CGRectMake(200, 0, 100, 20)];
[headerbutton setTitle:@"press me" forState:UIControlStateNormal];
[headerbutton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[headerbutton addTarget:self action:@selector(addingRows) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:headerbutton];
UILabel *sectionName = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 150, 20)];
[sectionName setText:@"Section Name"];
[sectionName setTextColor:[UIColor blackColor]];
[customView addSubview:sectionName];
return customView;
}
-(void)addingRows
{
rowS +=1;
[self.tableView reloadData];
}