web-dev-qa-db-ja.com

モーダルビューコントローラーを提示すると、ナビゲーションバーが非表示になります

ナビゲーションバーを備えたナビゲーションベースのアプリがありますが、View Controllerをスタックにプッシュする代わりに、ViewControllerをモーダルに提示する必要がある場合がいくつかあります。問題は、モーダルビューコントローラーを閉じると、ナビゲーションバーが非表示になり、(親ビュー)のサイズが変更されたことを除いて、すべてが期待どおりに機能することです。これは、ドキュメントによると予想される動作です。そのため、組み込みメソッドを呼び出すだけでナビゲーションバーを再表示できると考えました。私はすでに試しました

[self.navigationController setNavigationBarHidden:NO];

アニメーション版も成功しませんでした。

ドキュメントは、メソッドでこれについて説明しています

presentModalViewController: animated:

それが言う議論のセクションで、

IPhoneおよびiPodtouchデバイスでは、modalViewControllerのビューは常にフルスクリーンで表示されます」および「modalViewControllerプロパティを指定されたViewControllerに設定します。ビューのサイズを変更し、ビュー階層にアタッチします。」しかし、モーダルビューを閉じた後、このプロセスを元に戻す方法については、ドキュメントからはわかりませんでした。

他の誰かがこれを経験し、解決策を見つけましたか?

編集:私はこれと同じ問題を抱えているので、私自身の質問をする代わりに、私はこれに関する報奨金を後援しています。これは私の特定の状況です:

私の場合、モーダルビューコントローラーのナビゲーションコントローラー上にイメージピッカーを表示しています。

-(void) chooseImage {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        imagepicker = [[UIImagePickerController alloc] init];
        imagepicker.allowsEditing = NO;
        imagepicker.delegate = self;
        imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagepicker.navigationBar.opaque = true;
        imagepicker.wantsFullScreenLayout = NO;

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

            if (self.view.window != nil) {
                popoverController = [[UIPopoverController alloc] initWithContentViewController:imagepicker];

                [popoverController presentPopoverFromBarButtonItem:reset permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
            } else {}

        } else {
            [self.navigationController presentModalViewController:imagepicker animated:YES];   
        }
    }
}

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        [self.popoverController dismissPopoverAnimated:true];
    } else {
        [self.navigationController dismissModalViewControllerAnimated:YES];
    }
    //Save the image
}

-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        [self.popoverController dismissPopoverAnimated:true];
    } else {
        [self.navigationController dismissModalViewControllerAnimated:YES];
    }
}
17
EmphaticArmPump

次のように、UINavigationControllerからmodalViewControllerを提示および却下するようにしてください。

// show
[self.navigationController presentModalViewController:vc animated:YES];
// dismiss
[self.navigationController dismissModalViewControllerAnimated:YES];

ビューコントローラが実際にUINavigationControllerのスタック上にある場合、これはモーダルビューコントローラの表示と非表示を処理する正しい方法です。 UINavigationBarがまだ非表示になっている場合は、他にファンキーなことが起こっているため、コードを確認して何が起こっているのかを判断する必要があります。

編集

私はあなたのコードを私のアプリにコピーしました、そしてUIImagePickerControllerは首尾よく提示されて却下されました、そして私のUINavigationControllerのUINavigationBarはまだそこにありました。問題はあなたのアーキテクチャの他の場所にあると私は心から信じています。サンプルプロジェクト付きのZipをアップロードする場合は、見ていきます。

18

次のコードを試してみてください。

SettingsViewController *settings    =   [[SettingsViewController alloc] init];
UINavigationController *navcont = [[UINavigationController alloc] initWithRootViewController:settings];
[self presentModalViewController:navcont animated:YES];
[settings release];
[navcont release];

提示されたコントローラーにナビゲーションバーを表示するには、ナビゲーションコントローラーを提示する必要があります

11
Priyank Ranka

間違ったVCでViewControllerを提示すると、この動作が見られたと思います。ナビゲーションコントローラーまたは個々のVCでpresentModalViewControllerを呼び出していますか?

まだ行っていない場合は、navigationControllerから呼び出してみてください。

[self.navigationController presentModalViewController:myVC animated:YES];
3
Bob Spryn
AddContactVC *addController =[self.storyboard instantiateViewControllerWithIdentifier:@"AddContactVC"];
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:addController];
[self presentViewController:navigationController animated:YES completion: nil];

私のために働いているのはナビゲーションバーを示しています

1
Asad ali

これをチェックしてください。これは、UIViewControllerクラスリファレンスにあるAppleのドキュメントです。

モーダルビューは常にフルスクリーンモードで表示されることを明確に示しているため、ナビゲーションバーが非表示になることは明らかです。したがって、別のナビゲーションバーをモーダルビューに配置して、元に戻ります。

presentModalViewController:animated:
Presents a modal view managed by the given view controller to the user.

- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
Parameters
modalViewController
The view controller that manages the modal view.
animated
If YES, animates the view as it’s presented; otherwise, does not.
Discussion
On iPhone and iPod touch devices, the view of modalViewController is always presented full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.

Sets the modalViewController property to the specified view controller. Resizes its view and attaches it to the view hierarchy. The view is animated according to the transition style specified in the modalTransitionStyle property of the controller in the modalViewController parameter.

Availability
Available in iOS 2.0 and later.

これが、ナビゲーションコントローラーとともにビュー全体を非表示にすることがモーダルビューのデフォルトの動作であることを理解するのに役立つことを願っています。モーダルビューに別のナビゲーションバーを配置してナビゲートしてみてください。

このリンクでさらに確認できます

http://developer.Apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

1
Parth Bhatt

コントローラーをモデルとして提示すると、Viewコントローラーが全体ビューに表示されます。

モデルビューからナビゲーションコントローラーのプロパティにアクセスする場合は、別のナビゲーションコントローラー参照を作成する必要があり、それは以前と同じように続行されます。

これはあなたにとって役立つかもしれません。

1
Rajesh

このカテゴリを使用するための最良の解決策の1つMaryPopin https://github.com/Backelite/MaryPopin

0
Abo3atef

Xcodeには、あなたがしていることにかなり近いテンプレートがあります。結果から、[self.navigationController presentModalViewController:vc]と[self.navigationController dismissModalViewControllerAnimated:]を実行しようとしているのではなく、単に[self presentModalViewController:]と[self dismissModalViewControllerAnimated:]を実行しようとしていると思います。

テンプレートがこれをどのように実行するかを確認するには、xcode4.3の新しいプロジェクトウィザードを使用できます。おそらくそれはいくつかのガイダンスを提供します:

Xcode new project wizard utility template

その選択肢から、[次へ]を選択し、テストプロジェクトに名前を付け、[ユニバーサル]を選択し、自動参照カウントをオフにして、[次へ]をクリックし、必要な場所に保存します。

ここで、ターゲットをクリックして、テスト目的で展開ターゲットを4.3(または必要に応じて4.0)に切り替え、デバイスまたはiOS4.3シミュレーターに切り替えます。

最後に、作成されたAppDelegate.mのapplicationDidFinishLaunching:withOptions:に次のコードを代入します。

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.mainViewController = [[[MainViewController alloc] initWithNibName:@"MainViewController_iPhone"
                                                                        bundle:nil] autorelease];
    } else {
        self.mainViewController = [[[MainViewController alloc] initWithNibName:@"MainViewController_iPad"
                                                                        bundle:nil] autorelease];
    }
    UINavigationController* navigationController
      = [[UINavigationController alloc] initWithRootViewController:self.mainViewController];
    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];
    return YES;

これを実行しても、navigationBarは非表示になりません。テンプレートから作成されたMainViewController.mで、モーダルビューコントローラーを表示し、ナビゲーションコントローラーからではなくコントローラー自体からそれを閉じる方法を確認できます。テンプレートコードを自分のものに近づけるには、MainViewController.mにアクセスして、モーダルビューコントローラーの遷移スタイルを設定する行を削除します...

(もちろん、iOS 5では、ストーリーボードを使用すると、同じことがすべてモーダルセグエで達成できます...これは、これでmodalViewControllerを提示する5.0より前ではサポートされていないアプリに対してこれを行った方法ですファッション。)

0
john.k.doe