2013-03-14 5 views
1

Я реализовал этот настраиваемый элемент управления в своем проекте: Github page этот элемент управления добавляет почтовый ящик, как удалять, чтобы удалить/завершить функцию, которую я хотел бы использовать.UITextfield вмешивается в жесты салфетки

Единственная проблема, с которой я столкнулся при использовании этого, - это добавить UITextField в ячейку через раскадровки. Когда я добавляю один, ячейка перестает распознавать жесты и только позволяет мне взаимодействовать с UITextField.

У кого-нибудь есть средство для решения этой проблемы?

Редактировать: Вот метод инициализации TableViewCell. Сожалею.

- (void)initializer 
{ 
    _mode = MCSwipeTableViewCellModeSwitch; 

    _colorIndicatorView = [[UIView alloc] initWithFrame:self.bounds]; 
    [_colorIndicatorView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; 
    [_colorIndicatorView setBackgroundColor:[UIColor clearColor]]; 
    [self insertSubview:_colorIndicatorView belowSubview:self.contentView]; 

    _slidingImageView = [[UIImageView alloc] init]; 
    [_slidingImageView setContentMode:UIViewContentModeCenter]; 
    [_colorIndicatorView addSubview:_slidingImageView]; 

    _panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGestureRecognizer:)]; 
    [self addGestureRecognizer:_panGestureRecognizer]; 
    [_panGestureRecognizer setDelegate:self]; 
} 

и способ для обработки жест

- (void)handlePanGestureRecognizer:(UIPanGestureRecognizer *)gesture 
{ 
    UIGestureRecognizerState state   = [gesture state]; 
    CGPoint translation      = [gesture translationInView:self]; 
    CGPoint velocity      = [gesture velocityInView:self]; 
    CGFloat percentage      = [self percentageWithOffset:CGRectGetMinX(self.contentView.frame) relativeToWidth:CGRectGetWidth(self.bounds)]; 
    NSTimeInterval animationDuration  = [self animationDurationWithVelocity:velocity]; 
    _direction = [self directionWithPercentage:percentage]; 

    if (state == UIGestureRecognizerStateBegan) 
    { 
    } 
    else if (state == UIGestureRecognizerStateBegan || state == UIGestureRecognizerStateChanged) 
    { 
     CGPoint center = {self.contentView.center.x + translation.x, self.contentView.center.y}; 
     [self.contentView setCenter:center]; 
     [self animateWithOffset:CGRectGetMinX(self.contentView.frame)]; 
     [gesture setTranslation:CGPointZero inView:self]; 
    } 
    else if (state == UIGestureRecognizerStateEnded || state == UIGestureRecognizerStateCancelled) 
    { 
     _currentImageName = [self imageNameWithPercentage:percentage]; 
     _currentPercentage = percentage; 
     MCSwipeTableViewCellState state = [self stateWithPercentage:percentage]; 

     if (_mode == MCSwipeTableViewCellModeExit && _direction != MCSwipeTableViewCellDirectionCenter && [self validateState:state]) 
      [self moveWithDuration:animationDuration andDirection:_direction]; 
     else 
      [self bounceToOriginWithDirection:_direction]; 
    } 
} 
+0

Либо отправьте код, с которым у вас возникли проблемы, или просто вернитесь к парню, который сделал ваш контроль, и попросите его о помощи. Мы здесь, чтобы помочь, если у вас есть проблемы с кодом, и, видя это, мы можем вам помочь. –

+0

Извините. Я добавил код. – cherbear

+0

Коды вы отправили в полном порядке. Он должен работать. Где код для текстового поля? Вы добавляете его через раскадровку, но где код для этого, чтобы подключить его и запустить событие жестов? –

ответ

0

выяснял, как решить эту проблему. Я добавил подкласс UITextField к моему проекту, а затем импортировал заголовок UITextfield в пользовательский UITableViewCell. Добавление <UITextFieldDelegate> к @interface. Добавьте @property (nonatomic, strong, readonly) ItemLabel *label; // ItemLabel being the UITextField class в класс UITableViewCell, синтезируйте его в своей реализации.

Затем добавьте этот код в пользовательском инициализаторе или по умолчанию, если вы не имеете обычай одно:

_label = [[TehdaLabel alloc] initWithFrame:CGRectNull]; 
_label.textColor = [UIColor blackColor]; 
_label.font = [UIFont boldSystemFontOfSize:14]; 
_label.backgroundColor = [UIColor clearColor]; 
_label.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
_label.returnKeyType = UIReturnKeyDone; 
_label.delegate = self; 
[self addSubview:_label]; 

Затем добавить свои методы делегата для UITextField и быть веселым. Кажется, что UITextField вмешивался, потому что это не было подпунктом ячейки.

Смежные вопросы