1

テーブルビューがあり、セクション A で行をスワイプしてからセクション B で行を選択すると、セクション A でスワイプした行を選択したと見なされます。検証するブレークポイントを配置しましたが、それがそのセルであると考えられ、セクション B の行を選択したときにそれが呼び出されることを 100% 確信しています。

スワイプとは、セルの一部に指を置き、それをドラッグして (左右は関係ありません)、離すことを意味します。これはタップではないため、didSelectRowAtIndexPath を呼び出しません。

例:
indexpath をスワイプ A.1 indexpath
をタップ B.4
OS 呼び出し tableView:didSelectRowAtIndexPath: A.1

私は何か間違ったことをしていますか?何が問題になる可能性がありますか?

特定のセルでのタッチを処理する完全なコード:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    RDLogString(@"(%p) Received touches began", self);
    moveCount = 0;
    UITouch * touch = [touches anyObject];
    touchBegin = [touch locationInView: nil];
    [[self nextResponder] touchesBegan: touches withEvent: event];
}

- (void) touchesMoved: (NSSet * const)touches withEvent:(UIEvent * const)event {
    RDLogString(@"(%p) Received touches moved", self);
    moveCount++;
    [[self nextResponder] touchesMoved: touches withEvent: event];
}

- (void) touchesEnded: (NSSet * const)touches withEvent:(UIEvent * const)event {
    RDLogString(@"(%p) Received touches ended", self);
    if(![self checkUserSwipedWithTouches: touches]){
        [[self nextResponder] touchesEnded: touches withEvent: event];
    }
}

- (BOOL) checkUserSwipedWithTouches: (NSSet * const) touches {
    CGPoint touchEnd = [[touches anyObject] locationInView: nil];
    NSInteger distance = touchBegin.x - touchEnd.x;

    // This code shows an animation if the user swiped
    if(distance > SWIPED_HORIZONTAL_THRESHOLD){
        [self userSwipedRightToLeft: YES];
        return YES;
    } else if (distance < (-SWIPED_HORIZONTAL_THRESHOLD)) {
        [self userSwipedRightToLeft: NO];
        return YES;
    }

    return NO;
}
4

1 に答える 1

1

スワイプが検出されて処理されたときに、何も送信しない代わりに touchesCancelled を送信するように修正しました。アクションを処理したくない場合の対処方法に関する適切なドキュメントが見つかりませんでした。

動作するコード:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    moveCount = 0;
    UITouch * touch = [touches anyObject];
    touchBegin = [touch locationInView: nil];
    [[self nextResponder] touchesBegan: touches withEvent: event];
}

- (void) touchesMoved: (NSSet * const)touches withEvent:(UIEvent * const)event {
    moveCount++;
    [[self nextResponder] touchesMoved: touches withEvent: event];
}

- (void) touchesEnded: (NSSet * const)touches withEvent:(UIEvent * const)event {
    // If we DO NOT handle the touch, send touchesEnded
    if(![self checkUserSwipedWithTouches: touches]){
        [[self nextResponder] touchesEnded: touches withEvent: event];
    } else { // If we DO handle the touch, send a touches cancelled. 
        self.selected = NO;
        self.highlighted = NO;
        [[self nextResponder] touchesCancelled: touches withEvent: event];
    }
}
于 2010-07-13T17:16:48.163 に答える