代码之家  ›  专栏  ›  技术社区  ›  Nick

在表视图中滑动一行,单击“其他”,选择“滑动”

  •  1
  • Nick  · 技术社区  · 14 年前

    我所说的滑动是指将手指放在单元格的某个部分,然后将其拖动(左或右,无所谓),然后将其释放。这不会调用didselectrowatinexpath,因为它不是tap。


    在A.1上滑动
    轻触B.4
    操作系统调用表View: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;
    }
    
    1 回复  |  直到 14 年前
        1
  •  1
  •   Nick    14 年前

    我修复了它,当一个刷卡被检测和处理,而不是不发送任何东西,我现在发送一个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];
        }
    }