将此代码添加到您的 BUS2AppDelegate.h 文件中
@interface BUS2AppDelegate : UIResponder <UIApplicationDelegate>
{
UINavigationController *navController; //you have added this code?
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@end
在 BUS2AppDelegate.m 文件中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[BUS2ViewController alloc] initWithNibName:@"BUS2ViewController" bundle:nil];
// View Controller with each Navigational stack support.
navController = [[UINavigationController alloc]
initWithRootViewController:self.viewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
在您的第一个视图控制器中添加此代码
#import "AAlesund.h"
- (IBAction)secodVCBtnClicked:(id)sender {
AAlesund *aAlesund = [[AAlesund alloc] initWithNibName:@"AAlesund" bundle:nil];
self.navigationItem.title = @"Master";
[self.navigationController pushViewController:aAlesund animated:NO];
}
要在第二个视图控制器的导航栏中添加标题,请添加此代码
- (void)viewDidLoad
{
[super viewDidLoad];
UILabel *nav_title1 = [[UILabel alloc] initWithFrame:CGRectMake(60, 10, 220, 25)];
nav_title1.font = [UIFont fontWithName:@"Arial-BoldMT" size:18];
nav_title1.textColor = [UIColor whiteColor];
nav_title1.adjustsFontSizeToFitWidth = NO;
nav_title1.textAlignment = UITextAlignmentCenter;
nav_title1.text = @"Detail";
nav_title1.backgroundColor = [UIColor clearColor];
self.navigationItem.titleView = nav_title1;
}
这是输出。