xcode PageViewController 当前索引
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14813358/
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
PageViewController current index
提问by Dennis Sch?neborn
I want to set the value of a slider with the current index of a pageViewController. My idea is to use this method but i dont know how I get the index...
我想用 pageViewController 的当前索引设置滑块的值。我的想法是使用这种方法,但我不知道如何获得索引...
-(void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
if(completed)
{
//self.slider.value = THE INDEX;
}
}
回答by stringCode
I think you will have to implement custom method on your datasource, that will return you index of view controller. You very likely have array with ViewControllers in your datasource. so simple call like one below should do :
我认为您必须在数据源上实现自定义方法,这将返回视图控制器的索引。您的数据源中很可能有包含 ViewControllers 的数组。像下面这样的简单调用应该可以:
[pageViewController.datasource indexOfViewControler:[pageViewController.viewControllers]objectAtIndex:0]]; // index of viewcontroller is methond you need to implement on your datascource
回答by Ravindra Bagale
you have to implement the method for getting index. you can do this simply by adding your viewController in NSArray .
你必须实现获取索引的方法。你可以简单地通过在 NSArray 中添加你的 viewController 来做到这一点。
NSArray * viewControllers = [NSArray arrayWithObjects:firstViewController,secondViewController, nil];
& then get iindex like this:
&然后像这样得到iindex:
self.slider.value=[viewControllers indexOfObject:[pageViewControlle.viewController]];