我有
@property (weak, nonatomic) IBOutlet UIPageControl *pageCountControl;
这是我的代码。
在viewDidLoad内部
// I set the number of pages to 5.
self.pageCountControl.numberOfPages = 5;
// the main view will be the home page so I set it to the index 0
self.pageCountControl.currentPage = 0;
// Then I think that I have to dd the UIPageControl as subview to the current view.
[self.view addSubview:_pageCountControl];
[self.pageCountControl addTarget:self action:@selector(pageTurn:) forControlEvents:UIControlEventValueChanged];
}
// here is my question. I have a method that will be calling when the user moved through the pages. Do I have to create that page like the following code?
-(void)pageTurn:(UIPageControl *) page
{
int c = page.currentPage;
if(c==0)
{
// here
MainViewController *mainViewController = [self.childViewControllers objectAtIndex:self.pageCountControl.currentPage];
}
// and here
else if(c==1)
{
MainViewController *mainViewController =[self.childViewControllers objectAtIndex:c];
SecondViewController *secondViewController = [self.childViewControllers objectAtIndex:self.pageCountControl.currentPage];
}
else if(c==2)
{
SecondViewController *secondViewController =[self.childViewControllers objectAtIndex:c];
ThirdViewController *thirdViewController = [self.childViewControllers objectAtIndex:self.pageCountControl.currentPage];
}
}
我找到了一些关于使用UIPageControl在图像之间移动的教程,但是没有关于使用ViewControllers的教程。 我不确定我做对了吗? 谢谢。 后