iltercengiz / ICViewPager

MIT License
955 stars 235 forks source link

how to access viewpager method from childviewcontroller #93

Closed raitmoon closed 9 years ago

raitmoon commented 9 years ago

Hello,

I have a question. I want to know how to call viewpager's selectTabAtIndex method from childviewcontroller. I tried as below but it could not work.

if ([self.parentViewController isKindOfClass:[ViewPagerController class]]) {
    ViewPagerController *vc = (ViewPagerController *)self.parentViewController;
    [vc selectTabAtIndex:0];
}

Can you please give me any clue?

dhgillani commented 9 years ago

This method will help you

pragma mark - ViewPagerDelegate

raitmoon commented 9 years ago

Dhgillani, thanks for your comment. But I can not figure out, can you explain a bit more?

raitmoon commented 9 years ago

Sorry my question may not be good. It seems the parent view controller of the child view controller is not viewpagercontroller. And my program does not go into "if clause".

iltercengiz commented 9 years ago

Hey there, sorry for late reply. It won't work because view pager passes the content view controllers to UIPageViewController and as far as I know it doesn't add itself as parent view controller to the presented view controllers. One way to achieve your goal is adding a weak property to the content view controllers and assigning ViewPagerController subclass to it. This way you will be able to send messages to your ViewPagerController subclass to change its tab.

raitmoon commented 9 years ago

Hello, iltercengiz

Thanks for your reply! I could have done it as you adviced me.

Thank you