xcode UIPageControl 不调用 valueChanged 上的选择器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16016542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:13:28  来源:igfitidea点击:

UIPageControl not calling selector on valueChanged

iosobjective-cxcodeuiscrollviewuipagecontrol

提问by AddisDev

I am attempting to use a UIPageControlfor the first time and I can't seem to get it to call a function on UIControlEventValueChanged. Am I missing something here? I even tried a storyboard implementation but same broken results. I tried UIControlEventTouchUpInsideand other actions as well. None are calling the changePage:function below.

UIPageControl第一次尝试使用 a ,但似乎无法让它在UIControlEventValueChanged. 我在这里错过了什么吗?我什至尝试了故事板实现,但结果同样糟糕。我也尝试过UIControlEventTouchUpInside其他操作。没有人调用changePage:下面的函数。

In the .h:

在.h中:

@property (nonatomic, retain) UIPageControl *introPageControl;
-(IBAction)changePage:(id)sender;

In the .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 :(
}

采纳答案by MrBr

The UIControlEventValueChanged is only called when the UIPageControl view object was tapped.

UIControlEventValueChanged 仅在点击 UIPageControl 视图对象时调用。

回答by Peter Kreinz

Swift 3:

斯威夫特 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
}