-2

我在尝试启动导航控制器时遇到了可怕的麻烦。

基本上,我希望能够将新视图推送到控制器并点击后退按钮等。

这是我到目前为止的代码:

TestAppDelegate.h:

#import <UIKit/UIKit.h>

@interface TestAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

TestAppDelegate.m:

#import "TestAppDelegate.h"

@implementation TestAppDelegate

@synthesize window = _window;

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

- (void)applicationWillResignActive:(UIApplication *)application
{
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
     */
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    /*
     Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
     */
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    /*
     Called when the application is about to terminate.
     Save data if appropriate.
     See also applicationDidEnterBackground:.
     */
}

@end

但是我现在该怎么办?

我的意思是我应该把保存 NavigationController 的 .xib 文件放在哪里?

4

5 回答 5

1

这是UINavigationController类参考。其中链接了几个使用导航控制器的示例项目。随意下载它们并浏览它们以了解您应该如何使用它。

于 2012-06-26T15:11:10.237 回答
0

使用 xcode 中的故事板功能。它使这就像将 NavigationController 拖放到情节提要上一样简单。

这个链接对我帮助很大。

于 2012-06-26T15:13:25.297 回答
0

只需找到一个教程并运行它。像这个:

http://mobileorchard.com/how-to-make-an-iphone-app-part-4-navigation-controller/

于 2012-06-26T15:13:28.127 回答
0

创建新文件 > UIViewController 子类 > 使用 Xib 检查用户界面

#import <UIKit/UIKit.h>

@class WhatEverFileNameClass
@interface TestAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) WhatEverFileNameClass *viewController;

@end

.m

#import "TestAppDelegate.h"

@implementation TestAppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[WhatEverFileNameClass alloc] initWithNibName:@"WhatEverFileNameClass" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
于 2012-06-26T15:14:19.313 回答
0

首先创建您的视图控制器(新建文件 > UIViewController 子类 > 检查使用 Xib 获取用户界面)

然后设置你的UINavigationController

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

    ViewController *vc = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:vc];
    self.window.rootViewController = navController;
    [self.window makeKeyAndVisible];
    return YES;

}
于 2012-06-26T15:19:59.580 回答