Использование UIPageControl для навигации между ViewControllers

у меня есть

@property (weak, nonatomic) IBOutlet UIPageControl *pageCountControl;

Вот мой код.

Вид изнутриDidLoad

// 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. Я не уверен, правильно ли я делаю это? Спасибо. задний


person miss h    schedule 02.02.2015    source источник
comment
Возможно, это поможет вам: stackoverflow.com/ вопросы/20734673/   -  person beeef    schedule 03.02.2015
comment
Спасибо Биф, мне помогло.   -  person miss h    schedule 12.03.2015