請做以下的事情: 在AppDelegate.h
@property (nonatomic, retain) UINavigationController *navigationController;
在AppDelegate.m
@implementation AppDelegate
@synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
}
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
當你想要推下一個viewcontroller,你可以寫上面的代碼:
-(void)fontButtonPress{
FontViewController *fontViewController = [[FontViewController alloc] initWithNibName:@"FontViewController_iPhone" bundle:nil];
[self.navigationController pushViewController:fontViewController animated:YES];
}
讓我知道你是否有任何問題。
感謝
雅感謝您的幫助和..can你告訴我,爲什麼我們的appDelegate添加UINavigationController的工作原理? – user2353519 2013-05-06 05:54:45
如果我們需要按下按鈕並創建一個沒有UINavigationController的新堆棧,那我們能做什麼? – user2353519 2013-05-06 05:55:45
Page1 * button = [[Page1 alloc] initWithNibName:@「Page1」bundle:nil]; [self presentViewController:button animated:YES completion:nil]; – Ushan87 2013-05-06 06:01:53