0

ビューコントローラコンテナライブラリメールメールクライアントに追加しようとしています。アイデアは、ビューコントローラコンテナということです presents its child view controllers in two layers. It provides functionality for sliding the top view to reveal the views underneath it.

ライブラリの説明では、これは子controllerViewをその親にアタッチするための推奨される方法です。

if (![self.slidingViewController.underLeftViewController 
        isKindOfClass:[MenuViewController class]]) {
    self.slidingViewController.underLeftViewController  = 
        [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
  }

ここで、slidingViewControllerthe top-level instance of the view controller container. With this instance, you can set the view controllers underneath the top view and add panning.

ストーリーボードではなく、xibファイルを使用しています。代わりに私のコードは次のようになりました:

if (![self.slidingViewController.underLeftViewController 
        isKindOfClass:[MenuViewController class]]) {
    self.slidingViewController.underLeftViewController  =
         [[MenuViewController alloc] initWithNibName:@"Menu" bundle:nil];
}

しかし、そのコードを使用しています。このエラーが発生します。
-[__NSArrayM insertObject:atIndex:]: object cannot be nil

これは、次のことを実行しているslidingViewControllerにトレースできます。
[self.view insertSubview:_underTopViewController.view atIndex:0];

ドキュメントを見ると..instantiateViewControllerWithIdentifierinitWithNibNameには違いがあることがわかります。前者は常にオブジェクトを返しますが、後者は..のみをロードしますthe first time the view controller’s view is accessed

質問:そのビューが訪問されたかどうかに関係なく、initWithNibNameがロードされたviewcontrollerオブジェクトを返すようにするにはどうすればよいですか..instantiateViewControllerWithIdentifierと同様ですか?

4

1 に答える 1

1

次のように、プロパティにアクセスするだけviewでトリガーできるはずです。

if (![self.slidingViewController.underLeftViewController 
              isKindOfClass:[MenuViewController class]]) 
{
    MenuViewController *vc = 
      [[MenuViewController alloc] initWithNibName:@"Menu" bundle:nil];
    [vc view];  // <-- access the view and trigger loading
    self.slidingViewController.underLeftViewController  = vc;
}
于 2013-01-05T09:15:16.027 に答える