2013-09-25 59 views
6

我在tableviewcells中有UITextFields。当您滑过单元格而不是文本字段的一部分时,删除操作按预期方式出现。如果你滑过文本框,它会阻止删除弹出。左手手势滑过UITextField

我该如何解决这个问题,以便您可以滑过输入并且单元格将触发删除操作?

+0

你解决了这个问题吗? –

+0

没有。我重新设计了该问题的界面。 –

+0

尝试添加 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath。它的作品魅力 – Lightygalaxy

回答

2

我觉得这里的问题是,在文本字段中的触摸与您轻扫手势识别(可能连接到父视图)的干扰。我在放入UIScrollView的文本字段中遇到了类似的问题。

我通过在我的UITextField上覆盖了一个清晰的UIView来解决这个问题。然后,我为此清除视图分配了一个UITapGestureRecognizer,以便在用户点击该字段时将文本字段设置为第一响应者。否则,被刷卡被发送到父视图(滚动视图),它可以识别没有任何问题的滑动。这有点蹩脚,但它的工作。

这种情况有点不同于你的,但我认为这是同样的问题。这里是我的代码看起来像,希望这有助于:

// UIView subclass header 
@interface LSAddPageView : UIView 

@property (weak, nonatomic) IBOutlet UITextField *textField; // Connected to the UITextField in question 
@property (strong, nonatomic) UIView *textFieldMask; 
@property (assign, nonatomic) BOOL textFieldMaskEnabled; 

@end 

// UIView subclass implementation 
@implementation LSAddPageView 

- (void)awakeFromNib 
{ 
    [super awakeFromNib]; 

    _textFieldMask = [UIView new]; 
    _textFieldMask.backgroundColor = [UIColor clearColor]; 
    [self insertSubview:_textFieldMask aboveSubview:self.textField]; 
} 

- (void)layoutSubviews 
{ 
    [super layoutSubviews]; 

    _textFieldMask.frame = self.textField.frame; 
} 

- (BOOL)textFieldMaskEnabled 
{ 
    return _textFieldMask.hidden == NO; 
} 

- (void)setTextFieldMaskEnabled:(BOOL)textFieldMaskEnabled 
{ 
    _textFieldMask.hidden = !textFieldMaskEnabled; 
} 

@end 

然后在控制器:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    _addPageView = (LSAddPageView*)self.view; 

    _maskGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapMask:)]; 
    _maskGestureRecognizer.numberOfTapsRequired = 1; 
    _maskGestureRecognizer.numberOfTouchesRequired = 1; 
    [_addPageView.textFieldMask addGestureRecognizer:_maskGestureRecognizer]; 

    self.textField.delegate = self; // Set delegate to be notified when text field resigns first responder 
} 

- (void)didTapMask:(UIGestureRecognizer*)recognizer 
{ 
    _addPageView.textFieldMaskEnabled = NO; 
    [self.textField becomeFirstResponder]; 
} 

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField 
{ 
    _addPageView.textFieldMaskEnabled = YES; 
    return YES; 
} 
1

听起来像是你需要设置cancelsTouchesInView属性

yourGestureRecognizer.cancelsTouchesInView = NO; 
+0

它不适合我。 –