2011-12-07 10 views
4

私はちょうどPageControlのリンゴチュートリアルに行きたいと思っています。今私はこれを完全に理解していないことを指摘する必要があります。複雑なように見えるので、この質問が非常に明白であれば謝ります。UIPageControl新しいビューまたは別のコントローラをロードしています

リンゴが.plistからコンテンツを読み込んでいることに気付きました。あなたが持っているものがあればすべて素敵で簡単ですが、UILabelとUIImageViewがありますが、もし私がwanaをもっと複雑にするのであれば?どのようなページに応じて何か他のことをする各 "ページ"上のボタン、14の異なる変数のように各 "ページ"にしたい場合はどうなりますか?

私の質問はこれでしょう最初はスマートにしてください): ユーザーがページを切り替えると、別のコントローラーが読み込まれ、独自の.Xibファイルとビューが既にインターフェイスビルダーで作成されています。

ありがとうございます

答えて

0

はいあります。 UIPageViewControllerを使用します。 UIPageViewControllerには、ユーザーが左または右にスワイプするかどうかによって呼び出されるデータソースおよびデリゲートメソッドがあります。基本的には「おい、私にこのUIViewControllerの前後に表示するUIViewControllerを教えてください」と言います。

ここではサンプルです:

MyPageViewController.h

@interface MyPageViewController : UIPageViewController <UIPageViewControllerDataSource, UIPageViewControllerDelegate> 

@end 

MyPageViewController.m

#import "MyPageViewController.h" 

@implementation MyPageViewController 

- (id)init 
{ 
    self = [self initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll 
        navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal 
           options:nil]; 

    if (self) { 
     self.dataSource = self; 
     self.delegate = self; 
     self.title = @"Some title"; 

     // set the initial view controller 
     [self setViewControllers:@[[[SomeViewController alloc] init]] 
         direction:UIPageViewControllerNavigationDirectionForward 
         animated:NO 
         completion:NULL]; 
    } 

    return self; 
} 

#pragma mark - UIPageViewController DataSource methods 
- (UIViewController *)pageViewController:(UIPageViewController *)pvc 
     viewControllerBeforeViewController:(UIViewController *)vc 
{ 
    // here you put some logic to determine which view controller to return. 
    // You either init the view controller here or return one that you are holding on to 
    // in a variable or array or something. 
    // When you are "at the end", return nil 

    return nil; 
} 

- (UIViewController *)pageViewController:(UIPageViewController *)pvc 
     viewControllerAfterViewController:(UIViewController *)vc 
{ 
    // here you put some logic to determine which view controller to return. 
    // You either init the view controller here or return one that you are holding on to 
    // in a variable or array or something. 
    // When you are "at the end", return nil 

    return nil; 
} 

@end 

それです!

関連する問題