我有一个UITableView
填充了其上有按钮的单元。我希望这些按钮在编辑模式下也可以工作,但他们不会。看起来像UITableViewCell
上的手势识别器正在阻止按钮上的手势识别器。有没有人有任何关于解决这个问题的建议?在编辑模式下UITableViewCell上的按钮无法工作
ViewController.m:
- (void)viewDidLoad {
[super viewDidLoad];
self.items = [@[@"one", @"two", @"three", @"four"] mutableCopy];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"cellID"
forIndexPath:indexPath];
if (cell == nil) {
cell = [[TableViewCell alloc] init];
}
[cell.button setTitle: self.items[indexPath.row]
forState: UIControlStateNormal];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.items removeObjectAtIndex: indexPath.row];
}
}
TableViewCell.h:
@interface TableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIButton *button;
- (IBAction)buttonTapped:(id)sender;
@end
因此,buttonTapped:
被称为当一个小区不在编辑模式,但是当细胞处于编辑模式,该按钮不起作用。
你可能想告诉你使用,1键是如何添加的代码,2-如何启用“编辑”模式,3-您使用的任何手势识别器。 – zcui93
我指的是gestureRecognizers的UIKit中的使用。按钮在故事板 – poisoned