2017-05-08 15 views
-5

UIPageViewControllerを使用するアプリケーションを開発しているので、左から右にスワイプしてページ(ViewControllers)をナビゲートできます。私の元の投稿以来、私はコードを書いている。しかし、私は3つのエラーを受けています。UIPageViewControllerデリゲート、データソース&インターフェイスエラー

エラー1:プロパティ「デリゲート」タイプのオブジェクトに見つからない「IntroPages」 エラー2:プロパティ「のdataSource」タイプのオブジェクトに見つからない「IntroPages」 エラー3:「IntroPages」の目に見える@interfaceを宣言

3つのエラーはすべて、viewDidLoadの最初のセクション({}の中にあるセクション)にあります。最初の2つはviewDidLoadの下にあるコード用で、3番目の5行は下にあります。

デリゲートとデータソースは.hファイルで参照されます。なぜ彼らは見つからないのですか? Wyは 'IntroPages'のための目に見える@interfaceはありませんか?

コードは以下のとおりです。

IntroPages.h

#import <UIKit/UIKit.h> 

@interface IntroPages : UIViewController 
<UIPageViewControllerDelegate, UIPageViewControllerDataSource> 

@end 

ページが多すぎるされていない場合、あなたはこのように、自分のIDの配列でビューコントローラの配列を作成することができ

#import "IntroPages.h" 

@interface IntroPages() 

@end 

@implementation IntroPages 
{ 
    NSArray *myViewControllers; 
} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    self.delegate = self; 
    self.dataSource = self; 

    UIViewController *p1 = [self.storyboard 
          instantiateViewControllerWithIdentifier:@"Intro1ID"]; 
    UIViewController *p2 = [self.storyboard 
          instantiateViewControllerWithIdentifier:@"Intro2ID"]; 
    UIViewController *p3 = [self.storyboard 
          instantiateViewControllerWithIdentifier:@"Intro3ID"]; 
    UIViewController *p4 = [self.storyboard 
          instantiateViewControllerWithIdentifier:@"Intro4ID"]; 

    myViewControllers = @[p1,p2,p3,p4]; 

    [self setViewControllers:@[p1] 
        direction:UIPageViewControllerNavigationDirectionForward 
        animated:NO completion:nil]; 

    NSLog(@"loaded!"); 
} 


@end 
+0

どのような問題に直面していますか。投稿コード。 –

+0

私はどこにいるのかで投稿を編集しました。コードが含まれています。 – thejdah

答えて

0

IntroPages.m :

// assuming this 
@property (strong, nonatomic) IBOutlet UIPageViewController *pageViewController; 
@property (strong, nonatomic) NSArray *pages; 

// then, to setup, say these are the page ids... 
NSArray *vcIds = @[ @"id0", @"id1", ... ]; 
self.pages = [NSMutableArray array]; 

for (NSString *vcId in vcIds) { 
    UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:vcId]; 
    [self.pages addObject:vc]; 
} 

[self.pageViewController setViewControllers:self.pages direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; 

UIPageViewControllerDataSource与えられたvcの前後にview controllerを要求します。渡されたVCをページ配列で検索して正しい結果を得てください。

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { 
    NSUInteger index = [self.pages indexOfObject:viewController]; 
    return (index)? self.pages[index-1] : 0; 
} 

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { 
    NSUInteger index = [self.pages indexOfObject:viewController]; 
    return (index<self.pages.count-1)? self.pages[index+1] : self.pages[self.pages.count-1]; 
} 
+0

配列には5ページしかありません。 あなたが提供したコードはチュートリアルで見たものと似ています。このチュートリアルでは、タイトルとイメージが配列に含まれていましたが、実際にVCに割り当てられていませんでした。彼らはvcを作成するために配列からちょうど引っ張られました。私は配列から実際のvcsを呼び出すことは似ていると仮定しました。助けてくれてありがとう。 – thejdah

+0

これを使用しているストーリーボードには元のビューコントローラ - >ページビューコントローラ - >配列から呼び出されるビューが含まれていると仮定して正しいですか? – thejdah

+0

@thejdah、はい。実際には、 'self.storyboard'で提案されたコードでストーリーボードを取得するので、' self'であるvcがそれらのidを持つvcsと同じストーリーボードで定義されている必要があります。異なるストーリーボードでvcsを定義する必要がある場合は、教えてください。その方法を教えてください – danh

関連する問題