无法从touchesEnded发送参数

时间:2011-02-03 03:46:53

标签: iphone objective-c

我试图从我的touchesEnded处理程序中发送一个参数,如此......

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];
    CGPoint currentPosition = [touch locationInView:self.view];
    CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
    CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
    if (deltaX >= 0.3 && deltaY <= 100) { //horizontal swipe detected

               [self performSelector:@selector(refreshCover:)
                   withObject:nil afterDelay:0];
        if (gestureStartPoint.x < currentPosition.x) { //swipe right
            [self refreshCover:@"backward"];
            NSLog(@"swipe backward");
        } else { //swipe left
            [self refreshCover:@"forward"];
            NSLog(@"swipe forward");
        }       
    }
}

然后在refreshCover中,我只有:

    - (void)refreshCover:(NSString*)direction {

    NSLog(@"direction: %@", direction);
}

当用户滑动时,调用refreshCover,但未传递direction参数。如果我从其他任何地方调用[self refreshCover:@“forward”],那么参数将毫无问题地传递。

任何想法?提前谢谢。

1 个答案:

答案 0 :(得分:1)

问题在于此代码

[self performSelector:@selector(refreshCover:)
               withObject:nil afterDelay:0];

performSelector将调用该函数。我认为不需要此代码,因为您单独调用该函数