Objective C: UILongPressGestureRecognizer Error

2019-08-27 06:11发布

I am trying too put a UILongPressGestureRecognizer on my scrollView but it is not working.

It has an error after long touch saying: "Thread 1: Program Received Signal SIGABRT"

here my code:

- (void)viewDidLoad
{
    [super viewDidLoad];

    longPressToDrag = [[UILongPressGestureRecognizer alloc] initWithTarget:scrollView action:@selector(forLongPress:)];
    longPressToDrag.minimumPressDuration = 3.0;
    [scrollView addGestureRecognizer:longPressToDrag];

    [self pages];
}

- (void)forLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
    NSLog(@"Long Touch");
}

i have the error on my here:

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); //<--- Thread 1: Program received signal "SIGABRT"
    }
}

1条回答
何必那么认真
2楼-- · 2019-08-27 06:17

I think you're using the wrong target. Try changing

longPressToDrag = [[UILongPressGestureRecognizer alloc] initWithTarget:scrollView action:@selector(forLongPress:)];

to

longPressToDrag = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(forLongPress:)];
查看更多
登录 后发表回答