Objective C: UILongPressGestureRecognizer Error

久未见 提交于 2019-12-12 02:48:18

问题


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:


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:)];


来源:https://stackoverflow.com/questions/8937458/objective-c-uilongpressgesturerecognizer-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!