0

我有一个问题当然已经解决了,但我找不到答案。

我有一个具有三个主要视图的应用程序。就我而言,这意味着
我有主屏幕(屏幕 A),我可以转到屏幕 B 或屏幕 C。
我有(屏幕 B),我可以从中转到屏幕 A 或屏幕 C。
我有屏幕 C ,我可以从中转到屏幕 C可以转到屏幕 A 或屏幕 B。

我没有情节提要,我正在使用 presentModalViewController。所以我每次从孩子切换到其他屏幕时都想解雇父母

例如:( screen A->screen B取消之前调用屏幕 C 屏幕 A 被关闭)->screen C ->screen A(屏幕 A 再次创建,屏幕 B 被删除)

我尝试[self.presentingModalViewController dismissViewControllerAnimated];在按钮方法中使用其他屏幕调用,但它会引发异常。

我能做些什么?

谢谢!

4

4 回答 4

0

您可以这样做的一种方法是使用 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

更好的是,您可以将其作为具有三个视图控制器 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

您的应用程序导航是否基于?尝试这个:

 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 回答
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 或逐个呈现视图控制器

于 2013-01-29T13:47:58.197 回答