声明 UITouchGestures?
我正在使用 UISwipeGestureRecognizerDirectionRight 方法来更改应用程序中的视图,并且我在视图控制器的主文件中使用了以下代码,但似乎我需要在星号之后定义手势并将其声明为此版本错误状态: “swipeGesture 未声明”
-(void)createGestureRecognizers {
UISwipeGestureRecognizerDirectionRight * swipeGesture = [[UISwipeGestureRecognizerDirectionRight alloc]
initWithTarget:self
action:@selector (handleSwipeGestureRight:)];
[self.theView addGestureRecognizer:swipeGesture];
[swipeGesture release];
}
-(IBAction)handleSwipeGestureRight {
NC2ViewController *second2 =[[NC2ViewController alloc] initWithNibName:@"NC2ViewController" bundle:nil];
second2.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:second2 animated:YES];
[second2 release];
}
所以我的问题是如何在头文件中的星号后面声明“swipeGesture”或者我做错了什么?
谢谢
I'm working on using a UISwipeGestureRecognizerDirectionRight method to change views within an application and i have used the following code in the main file of the View Controller but it seems as though i need to define the gesture after the asterisk and declare it as this build error states:
"swipeGesture undeclared"
-(void)createGestureRecognizers {
UISwipeGestureRecognizerDirectionRight * swipeGesture = [[UISwipeGestureRecognizerDirectionRight alloc]
initWithTarget:self
action:@selector (handleSwipeGestureRight:)];
[self.theView addGestureRecognizer:swipeGesture];
[swipeGesture release];
}
-(IBAction)handleSwipeGestureRight {
NC2ViewController *second2 =[[NC2ViewController alloc] initWithNibName:@"NC2ViewController" bundle:nil];
second2.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:second2 animated:YES];
[second2 release];
}
So my question is how do i declare the "swipeGesture" after the asterisk in the header file or have i done something wrong?
Thank You
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UISwipeGestureRecognizerDirectionRight
是四个可能方向的枚举值。它不是您实例化来识别手势的类。使用 UISwipeGestureRecognizer 代替:此外,处理程序方法应该是:
因为在操作的选择器中,您在方法名称中放置了一个冒号,这意味着您希望它将发送者对象作为第一个参数传递。 (如果您不需要处理程序中的发送者,您也可以从选择器中删除冒号。)
最后,在处理程序中,
void
比IBAction
更合适,因为它不会从 xib 中的对象调用。但是,由于 IBAction 和 void 是同一件事,因此不会造成问题。UISwipeGestureRecognizerDirectionRight
is an enum value for the four possible directions. It is not a class you instantiate to recognize gestures. UseUISwipeGestureRecognizer
instead:Also, the handler method should be:
because in the selector for the action, you put a colon in the method name meaning you want it to pass the sender object as the first parameter. (You could also remove the colon from the selector instead if you don't need the sender in the handler.)
Finally,
void
is more appropriate thanIBAction
in the handler since it won't be called from an object in a xib. However, since IBAction and void are the same thing, it won't cause a problem.