2014-09-29 58 views
4

自iOS 8以來,我遇到了一個問題,在自定義UITableViewCell上滑動刪除手勢。UITableViewCell裏面的UITextField刷卡刪除問題

該問題似乎來自UITableViewCell的contentView內的UITextField。

這似乎是在iOS的8個問題,我在iOS版7相同的代碼工作正常

我如何能保持的UITextField編輯和滑動刪除手勢在同一時間工作?

+0

一些測試後,我可以證實這確實是一個iOS 8的問題。這個問題不會發生在iOS 7上。 – 2014-10-07 12:06:15

+0

如果你想我找到了解決方法。 – Yann86 2014-10-07 12:16:38

+0

那太棒了! – 2014-10-07 12:17:13

回答

6

以下爲我工作:

self.tableView.panGestureRecognizer.delaysTouchesBegan = YES; 
+0

更容易我會嘗試 – Yann86 2014-10-08 07:40:09

+0

這工作,謝謝。 – 2014-10-08 09:05:00

1

我發現我的問題的解決方法中的iOS 8

子類的UITextField和上也是UITextField的頂部添加視圖,則在「面具」視圖中添加UIGestureRecognizer爲單一的水龍頭。

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) 

@interface OMTextField : UITextField 
@property (nonatomic,retain) NSNumber*canBecomeFirstResponderFlag; 
@end 

@implementation OMTextField 

-(id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) { 

     _canBecomeFirstResponderFlag = @0; 

     UIView*mask = [[UIView alloc] init]; 
     mask.translatesAutoresizingMaskIntoConstraints = NO; 

     NSLayoutConstraint *maskT = [NSLayoutConstraint constraintWithItem:mask attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0]; 
     NSLayoutConstraint *maskB = [NSLayoutConstraint constraintWithItem:mask attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]; 
     NSLayoutConstraint *maskL = [NSLayoutConstraint constraintWithItem:mask attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0]; 
     NSLayoutConstraint *maskR = [NSLayoutConstraint constraintWithItem:mask attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0]; 

     [self addSubview:mask]; 
     [self addConstraints:@[maskT,maskB,maskL,maskR]]; 

     UITapGestureRecognizer *singleFingerTap = 
     [[UITapGestureRecognizer alloc] initWithTarget:self 
               action:@selector(handleSingleTap:)]; 
     [mask addGestureRecognizer:singleFingerTap]; 

    } 
    } 
    return self; 
} 

-(BOOL)canBecomeFirstResponder{ 

    BOOL canBecomeFirstResponder; 

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) { 

    canBecomeFirstResponder = [_canBecomeFirstResponderFlag boolValue]; 

    _canBecomeFirstResponderFlag = @0; 

    } 
    else{ 
    canBecomeFirstResponder = [self.delegate textFieldShouldBeginEditing:self]; 
    } 

    return canBecomeFirstResponder; 
} 

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer { 

    _canBecomeFirstResponderFlag = @1; 

    BOOL souldBecomeFirstResponder = [self.delegate textFieldShouldBeginEditing:self]; 

    if (souldBecomeFirstResponder) { 
    [self becomeFirstResponder]; 
    } 

} 

@end 
+0

感謝您的分享。儘管我已經將賞金賞給了其他答案,因爲實施起來要簡單得多。 – 2014-10-08 09:05:33