UITapGestureRecognizer calling another class

时光怂恿深爱的人放手 提交于 2020-01-16 03:18:09

问题


I am having an issue setting up a UITapGestureRecognizer calling a shared class across my app.

Basically I have a bunch of images that if tapped will popup another view with that image and comments. Instead of using initWithTarget using self I want to call the function from a shared class that can be loaded into each type of Navigation Controller.

I am able to initialize ImageClass *imageClass = [[ImageClass alloc]init] and call the functions fine by [imageClass DoThis] however when I add it to a UITapGestureRecognizer the app crashes.

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:imageClass action:@selector(DoThis)];

Also if I include the DoThis function and initWithTarget:self everything works as expected however I'd like to not write the DoThis function into every View Controller if possible I'd like it to fire directly from the UITapGestureRecognizer.

Thanks in advance for any insight you can give me into what I'm doing wrong.


回答1:


Alright basically I the imageClass object was getting deallocated every time a new image appeared. I moved that logic to the controller and all started working fine.

Thanks for helping out MSK!



来源:https://stackoverflow.com/questions/12287217/uitapgesturerecognizer-calling-another-class

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