UITapGestureRecognizer调用另一个类 [英] UITapGestureRecognizer calling another class
问题描述
我在设置 UITapGestureRecognizer
在我的应用程序中调用共享类时出现问题。
I am having an issue setting up a UITapGestureRecognizer
calling a shared class across my app.
基本上有一堆图像,如果轻拍将弹出另一个视图与该图像和评论。而不是使用 initWithTarget
使用 self
我想从一个共享类调用该函数,可以加载到每种类型导航控制器。
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.
我可以初始化 ImageClass * imageClass = [[ImageClass alloc] init]
但是当我把它添加到UITapGestureRecognizer应用程序崩溃。
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)];
此外,如果我包括 DoThis
initWithTarget:self
一切正常工作,但我想不写入 DoThis
函数到每个View Controller我想从 UITapGestureRecognizer
直接开火。
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.
推荐答案
基本上我的imageClass对象每次出现一个新的图片时都被释放。
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.
感谢您帮助MSK!
这篇关于UITapGestureRecognizer调用另一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!