Было бы здорово, если бы кто-то мог помочь достичь нижеследующего требования. В tableviewcell у меня есть горизонтальная прокрутка, которая будет динамически добавляться uibuttons. Пользователь может выбрать несколько кнопок из одной строки, но не может выбрать кнопку из разных строк. Например, если я уже выбрал кнопки (я должен выбрать одну или несколько кнопок) в строке1, а когда я нажимаю кнопку в строке2, выбранные кнопки в строке 1 должны быть отменены, и кнопка, которую я прослушивал в строке2, должна быть выбрана ,UITableViewCell UIButton Selection
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.timeslotScrollView.contentSize = CGSizeMake(500, 0);
cell.timeslotScrollView.scrollEnabled = YES;
cell.timeslotScrollView.showsHorizontalScrollIndicator = NO;
UIButton *button = [[UIButton alloc]init];
button.frame = CGRectMake(0, 0, 68, 35);
[button setTitle:@"abc" forState:UIControlStateNormal];
button.layer.borderWidth = 2;
button.layer.borderColor = [UIColor colorWithRed:0.23 green:0.71 blue:0.29 alpha:1.0].CGColor;
button.layer.cornerRadius = 3;
button.userInteractionEnabled = YES;
[button setTitleColor:[UIColor colorWithRed:0.23 green:0.71 blue:0.29 alpha:1.0] forState:UIControlStateNormal];
[button setTag:indexPath.row];
[button addTarget:self action:@selector(didTap:) forControlEvents:UIControlEventTouchUpInside];
UIButton *button1 = [[UIButton alloc]init];
button1.frame = CGRectMake(button.frame.origin.x+68+buttonSpace, 0, 68, 35);
[button1 setTitle:@"5 pm" forState:UIControlStateNormal];
[button1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
button1.layer.borderWidth = 2;
button1.layer.borderColor = [UIColor grayColor].CGColor;
button1.layer.cornerRadius = 3;
button1.userInteractionEnabled = YES;
[button1 setTag:indexPath.row];
[button1 addTarget:self action:@selector(didTap:) forControlEvents:UIControlEventTouchUpInside];
[cell.timeslotScrollView addSubview:button];
[cell.timeslotScrollView addSubview:button1];
}
return cell;
}
-(void)didTap:(id)sender
{
UIButton *pressedButton = (UIButton *)sender;
if (pressedButton.tag != selectedButton) {
[sender setBackgroundColor:[UIColor greenColor]];
selectedButton = pressedButton.tag;
}
else{
[sender setBackgroundColor:[UIColor clearColor]];
}
}
У вас есть код? Если да, отправьте его. Если нет, попробуйте решить вашу проблему, а затем вернитесь, если вы все еще не можете понять это. Спасибо –
@CalebKleveter Я обновил свой вопрос вместе с кодом, что я пробовал – user3310076
Что вы думаете? – Koen