у меня есть вид таблицы. И я добавляю две кнопки в каждую ячейку:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
newBtn = [[UIButton alloc]init];
newBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[newBtn setFrame:CGRectMake(250,10,25,55)];
[newBtn addTarget:self action:@selector(addLabelText:) forControlEvents:UIControlEventTouchUpInside];
[newBtn setTitle:@"+" forState:UIControlStateNormal];
[newBtn setEnabled:YES];
newBtn.hidden = YES;
[cell addSubview:newBtn];
subBtn = [[UIButton alloc]init];
subBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[subBtn setFrame:CGRectMake(280,10,25,55)];
[subBtn addTarget:self action:@selector(subtractLabelText:) forControlEvents:UIControlEventTouchUpInside];
[subBtn setTitle:@"-" forState:UIControlStateNormal];
[subBtn setEnabled:YES];
subBtn.hidden = YES;
[cell addSubview:subBtn];
}
return cell;
}
И я хочу сначала спрятать кнопки, затем, когда таблица находится в режиме «редактирования», я хочу, чтобы эти кнопки появлялись. и когда таблица выходит из режима редактирования, кнопки исчезают.
Я могу заставить одну из кнопок клеток сделать это.
- (IBAction)editButton:(id)sender
{
if (self.editing)
{
[self setEditing:NO animated:YES];
[self.myTableView setEditing:NO animated:YES];
EditButton.title = @"Edit";
subBtn.hidden = YES;
newBtn.hidden = YES;
}
else
{
[self setEditing:YES animated:YES];
[self.myTableView setEditing:YES animated:YES];
EditButton.title = @"Done";
subBtn.hidden = NO;
newBtn.hidden = NO;
}
}
Но проблема в том, что когда я делаю это, только самая последняя ячейка получает кнопки. Они появляются и исчезают именно тогда, когда я хочу, но только в последней ячейке! Никакие другие клетки не получают никаких кнопок, может кто-нибудь, пожалуйста, помогите мне! Большое спасибо!