0

我正在寻求您的帮助,因为我认为这是一个简单的问题,但我无法理解我的观点发生了什么。我正在显示由我的 UIViewController 启动的 OpenGL 视图,如下所示:

  //OpenGL view init
CGRect mainframe=CGRectMake(0,0,768,708);
GLView= [[OpenGLView alloc] initWithFrame:mainframe];

所以它显示得很好,但我试图添加一个滑动手势识别器来调用这个视图上的一个函数:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        ...  

        oneFingerSwipeRight =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(transitionCubeRight:)];
        oneFingerSwipeRight.direction=UISwipeGestureRecognizerDirectionRight;

        oneFingerSwipeLeft =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(transitionCubeLeft:)];
        oneFingerSwipeLeft.direction=UISwipeGestureRecognizerDirectionLeft;

        [self addGestureRecognizer:oneFingerSwipeRight];
        [self addGestureRecognizer:oneFingerSwipeLeft];

        ...
    }
    return self;
}

然后当视图出现时,我正在做向右或向左滑动的动作,这会出现在终端中:

2012-04-17 12:00:15.735 MultipleViewsApp[4372:f803]-[OpenGLView transitionCubeLeft:]:无法识别的选择器发送到实例 0xcd38bd0 2012-04-17 12:00:15.736 MultipleViewsApp[4372:f803]由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[OpenGLView transitionCubeLeft:]: unrecognized selector sent to instance 0xcd38bd0” 第一掷调用堆栈:(0x1764052 0x18f5d0a 0x1765ced 0x16caf00 0x16cace2 0x622e39 0x622143 0x6233cf 0x625a31 0x62598c 0x61e3e7 0x386812 0x386ba2 0x36d384 0x360aa9 0x293dfa9 0x17381c5 0x169d022 0x169b90a 0x169adb4 0x169accb 0x293c879 0x293c93e 0x35ea9b 0x2518 0x2475)

我的函数“transitionCubeLeft”/“transitionCubeLeft”只包含一个 NSLOG,但与此无关。如果有人能帮助我理解这个问题,我将不胜感激。谢谢

4

2 回答 2

2

我猜你还没有定义transitionCubeLeft方法。根据您使用的选择器,尝试找出它是否已定义并且方法的参数计数为 1。

于 2012-04-17T11:41:17.170 回答
1

看起来您已经transitionCubeLeft/transitionCubeRight定义了没有参数。

改变

 oneFingerSwipeRight =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(transitionCubeRight:)];
 oneFingerSwipeRight.direction=UISwipeGestureRecognizerDirectionRight;

 oneFingerSwipeLeft =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(transitionCubeLeft:)];
 oneFingerSwipeLeft.direction=UISwipeGestureRecognizerDirectionLeft;

 [self addGestureRecognizer:oneFingerSwipeRight];
 [self addGestureRecognizer:oneFingerSwipeLeft];

 oneFingerSwipeRight =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(transitionCubeRight)];
 oneFingerSwipeRight.direction=UISwipeGestureRecognizerDirectionRight;

 oneFingerSwipeLeft =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(transitionCubeLeft)];
 oneFingerSwipeLeft.direction=UISwipeGestureRecognizerDirectionLeft;

 [self addGestureRecognizer:oneFingerSwipeRight];
 [self addGestureRecognizer:oneFingerSwipeLeft];
于 2012-04-17T11:54:50.930 回答