There is a tableview consisting of two sections. Each of sections is filled from one of two arrays.
The task is to press the delete cell (for example, number 2) in the second section, the cell will be removed in the first - also under number 2, and in the reverse order, so that it also works
#import "ViewController.h" CGFloat tableViewHeaderHeigth = 50; CGFloat tableViewFooterHeight = 50; @interface ViewController () <UITableViewDelegate, UITableViewDataSource> @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSMutableArray *firstArray; @property (nonatomic, strong) NSMutableArray *secondArray; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.firstArray = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3", @"4", @"5", nil]; self.secondArray = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3", @"4", @"5", nil]; UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped]; tableView.dataSource = self; tableView.delegate = self; [self.view addSubview:tableView]; self.tableView = tableView; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView //ΠΊΠΎΠ»-Π²Π° ΡΠ΅ΠΊΡΠΈΠΉ { return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section==0) { return self.firstArray.count; } else if (section==1) { return self.secondArray.count; } return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *reUseId = @"Cell"; //ΠΠΎΠΈΡΠΊ ΡΡΠ΅ΠΉΠΊΠΈ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reUseId]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reUseId]; } if (indexPath.section == 0) { cell.textLabel.text = [self.firstArray objectAtIndex:indexPath.row]; } else { cell.textLabel.text = [self.secondArray objectAtIndex:indexPath.row]; } UIButton *button = [[UIButton alloc] init]; button.frame = cell.frame; button.backgroundColor = [UIColor clearColor]; [button addTarget:self action:@selector(didPressDeleteButton:) forControlEvents:UIControlEventTouchUpInside]; [cell addSubview:button]; return cell; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ return YES; } -(void)didPressDeleteButton:(id)sender{ [self.tableView setEditing:YES animated:YES]; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { if (indexPath.section == 0){ NSMutableArray *tempArray = self.firstArray.mutableCopy; [tempArray removeObjectAtIndex:indexPath.row]; self.firstArray = tempArray.mutableCopy; } else { NSMutableArray *tempArray = self.secondArray.mutableCopy; [tempArray removeObjectAtIndex:indexPath.row]; self.secondArray = tempArray.mutableCopy; } [self.tableView reloadData]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end Update
A good example. If you press the sting of the fifth cell, then the 5th cell from the bottom section should be removed.

[tempArray removeObjectAtIndex:indexPath.row]- and what does this line do? - zhenyab