SEL类型相当于C++中的函数指针。
@selector:(SEL) 也就是说@selector :后可以接收SEL类型的函数指针。
就我个人来看,selector就好比是一个非常灵活的函数指针。但是它要比C语言中的函数指针更加灵活,因为它的值并不是某个函数的地址,而仅仅是方法名。这一点比C++中的指向类成员指针要灵活得多,尽管它只是对方法(操作)的引用而无法引用数据成员(属性)。
不过,概念上,IMP类型才是一个方法指针类型。
默认的API函数,只能接受一个方向的滑动操作,因此使用selector来进行多个滑动操作
//---right swipe (default)---
UISwipeGestureRecognizer *swipeRihgtGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
[self addGestureRecognizer:swipeRihgtGesture];
[swipeRihgtGesture release];
//---left swipe---
UISwipeGestureRecognizer *swipeLeftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
swipeLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self addGestureRecognizer:swipeLeftGesture];
[swipeLeftGesture release];
-(IBAction) handleSwipeGesture:(UIGestureRecognizer *) sender {
UISwipeGestureRecognizerDirection direction = [(UISwipeGestureRecognizer *) sender direction];
switch (direction) {
case UISwipeGestureRecognizerDirectionRight:
[self movePrevMonth];
break;
case UISwipeGestureRecognizerDirectionLeft:
[self moveNextMonth];
break;
default:
break;
}
}