UINavigationController - 无法上手

时间:2012-06-26 15:07:28

标签: iphone objective-c ios

我在尝试使导航控制器正常运行时遇到了麻烦。

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

以下是我所熟悉的代码:

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文件?

5 个答案:

答案 0 :(得分:1)

这是UINavigationController Class Reference。链接在内的是使用导航控制器的几个示例项目。随意下载它们并查看它们应该如何使用它。

答案 1 :(得分:0)

在xcode中使用storyboard功能。这使得将NavigationController拖放到故事板上非常简单。

link给了我很多帮助。

答案 2 :(得分:0)

答案 3 :(得分:0)

创建新文件&gt; UIViewController子类&gt;使用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;
}

答案 4 :(得分:0)

首先创建你的viewcontroller(新文件&gt; UIViewController子类&gt;使用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;

}