16

UIPageViewController で特定のページ番号にジャンプする方法を見つけるのにほぼ 8 時間を費やしました...以下は私のプロジェクトの外観です

Ibooksっぽいアプリを作りたい---

ここに示されているコードから助けを得ました - http://www.ioslearner.com/tag/uipageviewcontroller-sample-code/

plist と UITableView を作成し、TableView から値を選択し、UIPageiewController に配置された webView に同じ値を表示しますが、問題は、Web ビューのページのみが変更され、UIPageViewController の実際のページ番号が変更されないことです....

質問を絞り込むと、次のようになります --- UIPageViewController でページ番号を切り替える方法はありますか? ... ???

4

5 に答える 5

6

スウィフトコード:

func goToPage(index: Int) {
    if index < viewControllers.count {
        pageVC!.setViewControllers([viewControllers[index]], direction: .Forward, animated: true, completion: nil)
    }
}
于 2016-01-18T15:40:08.113 に答える
6

ジャンプ先のページを管理するビュー コントローラーをインスタンス化してから、ページ ビュー コントローラーのsetViewControllers:direction:animated:completion:メソッドを呼び出して、新しいビュー コントローラーを渡す必要があります。

于 2012-07-05T12:57:03.637 に答える
2

私はこの機能を使用しています(私は常に横向き、2ページモードです)

-(void) flipToPage:(NSString * )index {


int x = [index intValue];
LeafletPageContentViewController *theCurrentViewController = [self.pageViewController.viewControllers   objectAtIndex:0];

NSUInteger retreivedIndex = [self indexOfViewController:theCurrentViewController];

LeafletPageContentViewController *firstViewController = [self viewControllerAtIndex:x];
LeafletPageContentViewController *secondViewController = [self viewControllerAtIndex:x+1 ];


NSArray *viewControllers = nil;

viewControllers = [NSArray arrayWithObjects:firstViewController, secondViewController, nil];


if (retreivedIndex < x){

    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];

} else {

    if (retreivedIndex > x ){

        [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:NULL];
      } 
    }
} 

これも必要かも

- (LeafletPageContentViewController *)viewControllerAtIndex:(NSUInteger)index {   

    if (([self.modelArray count] == 0) || (index >= [self.modelArray count])) {
        return nil;
    }
    LeafletPageContentViewController *dataViewController;
    dataViewController = [[LeafletPageContentViewController alloc]initWithNibName:@"LeafletPageContentViewController" bundle:nil];

    dataViewController.dataObject = [self.modelArray objectAtIndex:index];
    return dataViewController;

}
于 2012-08-10T09:13:53.580 に答える
2

@milijanの回答はうまくいきました。彼の答えの迅速なバージョンは次のとおりです。

func jumptoPage(index : Int) {

    let vc = viewControllerAtIndex(index)
    let direction : UIPageViewControllerNavigationDirection!

    if currentIndex < index {
        direction = UIPageViewControllerNavigationDirection.Forward
    }
    else {
        direction = UIPageViewControllerNavigationDirection.Reverse
    }

    if (currentIndex < index) {
        for var i = 0; i <= index; i++ {
            if (i == index) {
                self.newPageViewController.setViewControllers([vc], direction: direction, animated: true, completion: nil)
            }
            else {
                self.newPageViewController.setViewControllers([viewControllerAtIndex(i)], direction: direction, animated: false, completion: nil)
            }
        }
    }
    else {
        for var i = currentIndex; i >= index; i = i - 1 {
            if i == index {
                self.newPageViewController.setViewControllers([vc], direction: direction, animated: true, completion: nil)
            }
            else {
                self.newPageViewController.setViewControllers([viewControllerAtIndex(i)], direction: direction, animated: false, completion: nil)
            }
        }
    }
 currentIndex = index
}
于 2015-10-21T16:30:42.923 に答える