我第一次尝试使用UIPageControl
而我似乎无法调用UIControlEventValueChanged
上的函数。我在这里错过了什么吗?我甚至尝试过故事板实现,但结果却相同。我也试过UIControlEventTouchUpInside
和其他行动。没有人在下面调用changePage:
函数。
在.h:
@property (nonatomic, retain) UIPageControl *introPageControl;
-(IBAction)changePage:(id)sender;
在.m:
@synthesize introPageControl;
- (void)viewDidLoad {
[super viewDidLoad];
self.introPageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0,208,self.view.frame.size.width,36)];
self.introPageControl.numberOfPages = 4;
self.introPageControl.currentPage = 0;
[self.introPageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.introPageControl];
}
-(IBAction)changePage:(id)sender {
// NEVER GETS CALLED :(
}
答案 0 :(得分:3)
只有在点击UIPageControl视图对象时才会调用UIControlEventValueChanged。
答案 1 :(得分:1)
斯威夫特3:
pageControl.numberOfPages = 6
pageControl.currentPage = 0
pageControl.addTarget(self, action: #selector(pageControlTapHandler(sender:)), for: .touchUpInside)
...
func pageControlTapHandler(sender:UIPageControl) {
print("currentPage:", sender.currentPage) //currentPage: 1
}