0

我正在尝试(在 XCode 中)创建一个选项卡式应用程序,该应用程序在其中一个选项卡中包含一个 UINavigationController,用于显示“FourthViewController”,然后当在该“FourthViewController”中按下按钮时,一个新的“ SlideViewController" 被推到 UINavigationController 上(呸!)。我在理解如何使 UINavigationController 从 FourthViewController 或 SlideViewController 中推送新的 ViewController 时遇到问题。我包括了一个流程图和一些代码,试图让我更清楚我在做什么。(为了记录,这是一个餐厅的应用程序,这就是为什么会有像“shrimpquesadilla.jpg”这样的名字。)

以下是流程图的链接,我没有足够的声誉将其嵌入帖子中:http: //i.imgur.com/lZVdn.jpg

DemoTabbedAppDelegate.h

    @interface DemoTabbedAppDelegate : UIResponder <UIApplicationDelegate,
                                     UITabBarControllerDelegate>
    {
        UINavigationController *globalUINavigationController;
    }
    ... //other syntheses
    @synthesize globalUINavigationController;

DemoTabbedAppDelegate.m

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
                    (NSDictionary *)LaunchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        ... /creating the first three tab ViewControllers
        globalUINavigationController = [[UINavigationController alloc] initWithNibName:
                    @"DemoTabbedFourthViewController" bundle:nil];
        ... //setting last tab title and image
        UIViewController *viewController4 = [[DemoTabbedFourthViewController alloc]
                    initWithNibName:@"DemoTabbedFourthViewController" bundle:nil];
        [globalUINavigationController pushViewController:viewController4 animated:YES];
        ... //Starting the TabBarController and making it the rootViewController
    }

DemoTabbedFourthView.m

    //initialization and all that junk
    - (void)goToSlide:(UIImage *)image
    {
        DemoTabbedSlideViewController *d = [[DemoTabbedSlideViewController alloc]
                                            initWithImage:image];
        [globalUINavigationController pushViewController:d animated:YES];
        NSLog(@"test");
        //what goes here to call push on the UINavigationController?
    }

    - (void)clickQuesadilla:(id)sender
    {
        [self goToSlide:[UIImage imageNamed:@"shrimpquesadilla.jpg"]];
    }

DemoTabbedSlideViewController

    - (id)initWithImage:(UIImage *)image
    {
        self = [super init];
        imageView = [[UIImageView alloc] initWithImage:image]; 
        NSLog(@"test 2");
        return self;
    }

如果您需要更多信息,请告诉我,我已尽力说明这一点。感谢您的时间。

4

2 回答 2

2

我认为问题可能在于您如何初始化导航控制器。当您实例化导航控制器时,请尝试使用initWithRootViewController:而不是initWithNibName:.

此外,从您的 DemoTabbedFourthView 的 .m 中,您可以通过访问其navigationController属性然后pushViewController:animated:从中调用来获取指向它所在的导航控制器的指针:

[self.navigationController pushViewController:d animated:YES];
于 2012-07-25T20:43:29.643 回答
0

这种类型的应用程序实际上是 Storyboards 的典型代表。你有什么理由不喜欢使用它们吗?

您可以轻松地在所有这些视图之间布置带有 Segue 的 Storyboard,并让框架为您处理所有视图之间的导航。

于 2012-07-25T20:46:32.270 回答