0

もちろん解決された問題がありますが、その答えが見つかりませんでした。

3 つの主要なビューを持つアプリケーションがあります。私の場合、
メイン画面 (画面 A) があり、画面 B または画面 C に移動できることを意味します。画面 A または画面 C に
移動できる (画面 B) があります。
画面Aまたは画面Bに移動できます。

ストーリーボードがなく、presentModalViewController を使用しています。だから私は子から他の画面に切り替えるたびに親を却下したい

例: screen A->screen B (画面 C を呼び出す前に画面 A を閉じる) ->screen C ->screen A(画面 A を再度作成し、画面 B を削除する)

他の画面呼び出しのボタンメソッドで使用しようとし[self.presentingModalViewController dismissViewControllerAnimated];ましたが、例外がスローされます。

私に何ができる?

ありがとう!

4

4 に答える 4

0

3つのビューコントローラーA、B、Cを備えたTabBarベースのアプリケーションとして作成すると、ビューを簡単に切り替えることができます。

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewControllerA = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
UIViewController *viewControllerB = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
UIViewController *viewControllerC = [[ThirdViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewControllerA, viewControllerB,viewControllerC, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
于 2013-01-29T13:27:08.257 に答える
0

これを行う 1 つの方法は、navigationController を使用して、プッシュ、ポップ、またはポップしてから適切にプッシュすることです。

または、NSNotifications を使用して、親の viewController に子を却下するように指示することもできます。

[[NSNotificationCenter defaultCenter] postNotificationName:@"switchToViewB" object:nil userInfo:nil];

親は、通知を受け取ったときにメソッド switchToViewB を呼び出します。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(switchToViewB:) name:@"switchToViewB" object:nil];
于 2013-01-29T13:40:46.870 に答える
0

仕様では、-(void)dismissModalViewControllerAnimated: メソッドについて次のように述べています。

If you call this method on the presented view controller itself,
however, it automatically forwards the message to the presenting view controller.
If you present several view controllers in succession, and thus build a stack of 
presented    view controllers, calling this method on a view controller lower in
the stack dismisses its immediate child view controller and all view controllers 
above that child on the stack.

したがって、あなたの例で ScreenA を却下すると、ScreenB も却下されます。

そのようなアプローチの代わりに、UINavigationBar、UITabBar、または現在のビューコントローラーを1つずつ使用できます

于 2013-01-29T13:47:58.197 に答える
0

アプリケーションのナビゲーションはベースですか? これを試して:

 YourABCController *controllerObj = [[YourABCController alloc] initWithNibName:@"YourABCController" bundle:nil];

UINavigationController *navcont = [[UINavigationController alloc] initWithRootViewController:controllerObj];

[self presentModalViewController:navcont animated:YES];

[commentsViewControllerObj release];
于 2013-01-29T13:23:27.280 に答える