2013-06-22 41 views
0

我在代码中有ViewControllers A和B.将self.presentingViewController呈现给前景

我按下按钮时呈现B.然后在B中添加一个导航栏,其中有一个名为“返回上一屏幕”的导航项。然后,我尝试做这样的逻辑:当按下导航项目,执行下面的代码返回到B的presentingViewController,其中,在这种情况下,我认为这是A.

[self presentViewController:self.presentingViewController animated:YES completion:nil]; 

可惜不显示向上。我在lldb中使用“print [self.presentingViewController class]”命令,我可以看到这个类是A.我做错了什么?

回答

1

如果 “A介绍B” 由presentViewController:动画:完成:那么你可以通过一些回这样的:

- (void) back: (id)sender 
{ 
    [[self presentingViewController] dismissViewControllerAnimated:YES completion:nil]; 
} 
+0

这工作正常。这很奇怪,我的代码根本不起作用。 – newguy

0

为什么不添加UINavigationController“A”?那么你的逻辑更好,更容易。

只要按照我的代码。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 

    self.AViewController = [[AViewController alloc] init]; 
    self.navCon = [[UINavigationController alloc] initWithRootViewController:self.AViewController]; 
    self.window.rootViewController = self.navCon; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 
+0

是的,我知道。但我不想让UINavigationController显示在我的第一页上。除此之外,我也想知道为什么我的代码不工作,因为逻辑似乎很好。 – newguy