我有一個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