Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UIPageViewController iOS 8的下一页按钮-objC_Ios_Objective C_Button_Uipageviewcontroller - Fatal编程技术网

UIPageViewController iOS 8的下一页按钮-objC

UIPageViewController iOS 8的下一页按钮-objC,ios,objective-c,button,uipageviewcontroller,Ios,Objective C,Button,Uipageviewcontroller,实际上,我正在尝试使用PageViewController填充图库。我成功地将滚动图像带到视图中,但是,我使用了页面视图控制器中的“下一步”和“上一步”按钮,因为我使用了这行代码,所以无法正常工作 - (IBAction)previousButtonPressed:(id)sender { PageContentViewController *startingViewController = [self viewControllerAtIndex:0]; NSArray *vie

实际上,我正在尝试使用PageViewController填充图库。我成功地将滚动图像带到视图中,但是,我使用了页面视图控制器中的“下一步”和“上一步”按钮,因为我使用了这行代码,所以无法正常工作

- (IBAction)previousButtonPressed:(id)sender {
    PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
    NSArray *viewControllers = @[startingViewController];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
}

- (IBAction)nextButtonPressed:(id)sender {
    PageContentViewController *startingViewController = [self viewControllerAtIndex:+1];
    NSArray *viewControllers = @[startingViewController];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
    }
由于我在-(iAction)下一个按钮按下时使用了viewControllerAtIndex:+1:(id)sender我只在第一次点击按钮操作时,按钮操作才起作用。 提前感谢

检查此代码:-

- (void)changePage:(UIPageViewControllerNavigationDirection)direction {
    NSUInteger pageIndex = ((FooViewController *) [_pageViewController.viewControllers objectAtIndex:0]).pageIndex;
    if (direction == UIPageViewControllerNavigationDirectionForward){
        pageIndex++;
    }else {
        pageIndex--;
    }
    YourViewController *viewController = [self  viewControllerAtIndex:pageIndex];
    if (viewController == nil) {
        return;
    }
    [_pageViewController setViewControllers:@[viewController] direction:direction animated:YES completion:nil];
}
//上一个按钮

- (IBAction)previousButtonPressed:(id)sender {
    [self changePage:UIPageViewControllerNavigationDirectionReverse];
}
//下一个按钮

- (IBAction)nextButtonPressed:(id)sender {
    [self changePage:UIPageViewControllerNavigationDirectionForward];
}
检查此代码:-

- (void)changePage:(UIPageViewControllerNavigationDirection)direction {
    NSUInteger pageIndex = ((FooViewController *) [_pageViewController.viewControllers objectAtIndex:0]).pageIndex;
    if (direction == UIPageViewControllerNavigationDirectionForward){
        pageIndex++;
    }else {
        pageIndex--;
    }
    YourViewController *viewController = [self  viewControllerAtIndex:pageIndex];
    if (viewController == nil) {
        return;
    }
    [_pageViewController setViewControllers:@[viewController] direction:direction animated:YES completion:nil];
}
//上一个按钮

- (IBAction)previousButtonPressed:(id)sender {
    [self changePage:UIPageViewControllerNavigationDirectionReverse];
}
//下一个按钮

- (IBAction)nextButtonPressed:(id)sender {
    [self changePage:UIPageViewControllerNavigationDirectionForward];
}

Chandan的答案非常有效。 在swift 3.0中检查此项

func changePage(direction:UIPageViewControllerNavigationDirection)
{
    var pageIndex = (pageViewController.viewControllers?[0] as! SliderContentVC).pageIndex
    if(direction == UIPageViewControllerNavigationDirection.forward)
    {
        pageIndex = pageIndex! + 1
    }
    else
    {
        pageIndex = pageIndex! - 1
    }
    let viewController = self.viewControllerAtIndex(index: pageIndex!)
    if(viewController == nil)
    {
        return;
    }
    else
    {
        self.pageViewController.setViewControllers([viewController!], direction: direction, animated: true, completion: nil)
    }
}
//上一次单击

@IBAction func btnGoBack_Click(_ sender: Any)
{
    self.changePage(direction: .reverse)
}
//回击

@IBAction func btn_GoForward_Click(_ sender: Any)
{
    self.changePage(direction: .forward)
}
//视图索引法

func viewControllerAtIndex(index : Int) -> UIViewController?
{
    if(index < 0 || index >= MAX_COUNT)
    {
        return nil
    }
    let pageContentViewController = self.storyboard?.instantiateViewController(withIdentifier: "SliderContentVC") as! SliderContentVC
    pageContentViewController.pageIndex = index
    return pageContentViewController
}
func viewControllerAtIndex(index:Int)->UIViewController?
{
如果(索引<0 | |索引>=最大计数)
{
归零
}
将pageContentViewController=self.storyboard?.InstanceEviewController(标识符为:“SliderContentVC”)设为!SliderContentVC
pageContentViewController.pageIndex=索引
返回页面内容视图控制器
}

Chandan的答案非常有效。 在swift 3.0中检查此项

func changePage(direction:UIPageViewControllerNavigationDirection)
{
    var pageIndex = (pageViewController.viewControllers?[0] as! SliderContentVC).pageIndex
    if(direction == UIPageViewControllerNavigationDirection.forward)
    {
        pageIndex = pageIndex! + 1
    }
    else
    {
        pageIndex = pageIndex! - 1
    }
    let viewController = self.viewControllerAtIndex(index: pageIndex!)
    if(viewController == nil)
    {
        return;
    }
    else
    {
        self.pageViewController.setViewControllers([viewController!], direction: direction, animated: true, completion: nil)
    }
}
//上一次单击

@IBAction func btnGoBack_Click(_ sender: Any)
{
    self.changePage(direction: .reverse)
}
//回击

@IBAction func btn_GoForward_Click(_ sender: Any)
{
    self.changePage(direction: .forward)
}
//视图索引法

func viewControllerAtIndex(index : Int) -> UIViewController?
{
    if(index < 0 || index >= MAX_COUNT)
    {
        return nil
    }
    let pageContentViewController = self.storyboard?.instantiateViewController(withIdentifier: "SliderContentVC") as! SliderContentVC
    pageContentViewController.pageIndex = index
    return pageContentViewController
}
func viewControllerAtIndex(index:Int)->UIViewController?
{
如果(索引<0 | |索引>=最大计数)
{
归零
}
将pageContentViewController=self.storyboard?.InstanceEviewController(标识符为:“SliderContentVC”)设为!SliderContentVC
pageContentViewController.pageIndex=索引
返回页面内容视图控制器
}

对于上一个和下一个按钮,您希望视图控制器的索引为currentViewControllerIndex-1和currentViewControllerIndex+1,而不是o和1。跟踪当前索引并相应地传递下一个或上一个索引。对于上一个和下一个按钮,您希望视图控制器位于索引currentViewControllerIndex-1和currentViewControllerIndex+1,而不是o和1。跟踪当前索引,并相应地传递下一个或上一个索引。做得很好。在搜索了这么多不好的答案后,感谢您的回答。什么是FooViewController,我在数组中有视图控制器。如何在中转到下一个vcuipagedviewcontroller@satFooViewController只是我使用过的UIViewController。您可以使用您的自定义控制器名称而不是FooViewController。@Chandan我使用的vc数组类似于UIViewController*tuto1=[tutorialStoryboard InstanceDeviceController WithiIdentifier:@“firstVc”];UIViewController*tuto2=[tutorialStoryboard实例化设备控件标识符:@“secondvc”];UIViewController*tuto3=[tutorialStoryboard InstanceDeviceController的标识符:@“TermsAndConditionsVC”];UIViewController*tuto4=[tutorialStoryboard InstanceDeviceController的标识符:@“PermissionsVC]”;UIViewController*tuto5=[tutorialStoryboard实例化设备控制器标识符:@“MobileNumberVC”]@Chandan MyViewController=@[tuto1,tuto2,tuto3,tuto4,tuto5];在pagedvc中,我使用了两个按钮,如果我在showld中单击按钮,则转到下一步,如果我单击按钮,则应返回,我在vc中没有使用任何按钮,我只使用了2个按钮来完成这项非常好的工作..在搜索了这么多错误的答案后,感谢您的回答。什么是FooViewController,我有一个数组中的视图控制器。如何转到中的下一个vcuipagedviewcontroller@satFooViewController只是我使用过的UIViewController。您可以使用您的自定义控制器名称而不是FooViewController。@Chandan我使用的vc数组类似于UIViewController*tuto1=[tutorialStoryboard InstanceDeviceController WithiIdentifier:@“firstVc”];UIViewController*tuto2=[tutorialStoryboard实例化设备控件标识符:@“secondvc”];UIViewController*tuto3=[tutorialStoryboard InstanceDeviceController的标识符:@“TermsAndConditionsVC”];UIViewController*tuto4=[tutorialStoryboard InstanceDeviceController的标识符:@“PermissionsVC]”;UIViewController*tuto5=[tutorialStoryboard实例化设备控制器标识符:@“MobileNumberVC”]@Chandan MyViewController=@[tuto1,tuto2,tuto3,tuto4,tuto5];在pagedvc中,我使用了2个按钮,如果我在showld中单击按钮,则转到下一步,如果我单击按钮,则应返回,我在vc中没有使用任何按钮,我仅使用2个按钮来执行此操作