1

私はiTunesで素晴らしいスタンフォードcs193pコースをフォローしていて、今は講義#7と宿題#3にいます。

iPadでSplitViewControllerを正しく機能させようとしていますが、デバイスの向きが変わったときにUISplitViewControllerDelegateデリゲートメソッドが呼び出されないようです。

これが私がこれまでに得たものです:

-新しいiPadストーリーボードを作成し、UIViewControllerをマスター(CalculatorViewController)として、別のUIViewControllerを詳細(GraphViewController)としてSplitViewControllerを追加しました。私はすべてを正しく行ったと思います。

-私のGraphViewController.hは、UISplitViewControllerDelegateプロトコルを実装しています。

@interface GraphViewController : UIViewController <UISplitViewControllerDelegate>

-私のGraphViewController.mは、SplitViewControllerデリゲートをそれ自体に設定します。

- (void)awakeFromNib {
    [super awakeFromNib];
    self.splitViewController.delegate = self;
}

-私のGraphViewController.mは、必要なメソッドを実装しています。

// asks the delegate whether the first view controller should be hidden for the specified orientation
- (BOOL)splitViewController:(UISplitViewController *)svc 
   shouldHideViewController:(UIViewController *)vc 
              inOrientation:(UIInterfaceOrientation)orientation
{
    // only show the master controller in landscape mode
    return UIInterfaceOrientationIsPortrait(orientation);
}

// tells the delegate that the specified view controller is about to be hidden (must add a popover button)
- (void)splitViewController:(UISplitViewController *)svc 
     willHideViewController:(UIViewController *)aViewController 
          withBarButtonItem:(UIBarButtonItem *)barButtonItem 
       forPopoverController:(UIPopoverController *)pc
{
    barButtonItem.title = aViewController.title;

    // add the button to the toolbar
    NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
    [toolbarItems insertObject:barButtonItem atIndex:0];
    self.toolbar.items = toolbarItems; 
}

// tells the delegate that the specified view controller is about to be shown again (must remove popover button)
- (void) splitViewController:(UISplitViewController *)svc 
      willShowViewController:(UIViewController *)aViewController 
   invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{    
    // hide the bar button item on the detail controller
    NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
    [toolbarItems removeObject:barButtonItem];
    self.toolbar.items = toolbarItems;
}

-私のGraphViewController.mは、すべての方向をサポートしています。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return YES; // support all types of orientation
}

これで、アプリケーション(SnowLeopardのXcode4.2、iOS 5.0、iPad Simulator 5.0)を実行すると、splitViewController:willHideViewController:withBarButtonItem:forPopoverController:メソッドが呼び出され、マスタービューが非表示になり、ボタンが詳細ビューに表示されます。マスタービューをPopOverで表示します(私はポートレートモードになっているため)。

ただし、デバイスの向きを(ランドスケープモードに...まだシミュレーターを使用して)変更しても、何も起こらず、上記のメソッドは再度呼び出されません。マスタービューが非表示になり、PopOverボタンが表示されたままになりますが、実際には、マスタービューを表示し、PopOverボタンを非表示にします。

私は何が間違っているのですか?これは私のコード、Xcode、シミュレーターの問題ですか?

4

1 に答える 1

1

問題が解決しました!

他の人に役立つかもしれない場合に備えて、私が忘れていたことを次に示します。

私の CalculatorViewController (SplitViewController マスター) では、iPhone ではなく、iPad の横方向への向きの変更を許可する必要がありました。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    if (self.splitViewController) return YES; 
    else return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}

GraphViewController (SplitViewController Detail) に対して実行しましたが、CalculatorViewController に対して実行するのを忘れていました... 私のミスです!

于 2013-01-10T16:30:35.687 に答える