2012-06-26 4 views
-2

У меня ужасная проблема с попыткой получить навигационный контроллер вверх и вниз.UINavigationController - не может начаться

В принципе, я хочу, чтобы иметь возможность выдвинуть новые взгляды на контроллер и нажмите кнопку возврата и т.д.

Вот код, у меня есть ГНФАР:

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 

Но что же мне теперь делать?

Я имею в виду, где я могу поместить файл .xib, который содержит NavigationController?

+0

какая версия Xcode вы используете? – danh

+0

Ваш код до сих пор является пустым проектом iOS. : | – Peres

+0

Xcode 4.2 Не хотите использовать раскадровки, поскольку я никогда не использовал их до – Eamorr

ответ

0

Создать свой ViewController первый (New File> Подкласс 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; 

} 
+0

ОК, я сделал это и, похоже, сработал, но я бы хотел вернуться к кнопкам и так далее. Разве это не UINavigationController? Разве мне не нужно класть одну из них в один из моих xibs? – Eamorr

+1

Вы можете получить только кнопку «Назад» в панели навигации, если вы из своего ViewController нажимаете на контроллер другого вида в стеке. –

1

Вот UINavigationController Class Reference. Связанные внутри - несколько примеров проектов, в которых используется навигационный контроллер. Не стесняйтесь загружать их и просматривать их, как вы должны их использовать.

0

Используйте функцию раскадровки в xcode. Это делает это так же просто, как перетаскивание NavigationController на раскадровку.

Это link помогло мне много.

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; 
} 
+0

Эй, я не совсем понимаю это. Почему вы используете viewController, когда мне нужен навигационный контроллер? – Eamorr

Смежные вопросы