タイトル画面→遷移→UINavigationControllerのように途中からナビゲーションバーを出す。(ヘッダーファイルはいじってないので省略)
###ViewController.m
#import "ViewController.h"
#import "NextViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor grayColor];
UILabel *label= [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMidX(self.view.bounds)-130, CGRectGetMidY(self.view.bounds)-20, 260, 40)];
label.text = @"最初のビューコントローラーさん";
label.textColor = [UIColor whiteColor];
[self.view addSubview:label];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
NextViewController *next = [[NextViewController alloc]init];
[self presentViewController:next animated:YES completion:nil];
}
@end
###NextViewController.m
#import "NextViewController.h"
#import "ThirdViewController.h"
@interface NextViewController ()
@end
@implementation NextViewController
- (void)viewDidLoad {
self.view.backgroundColor = [UIColor yellowColor];
UILabel *label= [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMidX(self.view.bounds)-140, CGRectGetMidY(self.view.bounds)-20, 280, 40)];
label.text = @"ネクストビューコントローラーさん";
label.textColor = [UIColor blackColor];
[self.view addSubview:label];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
ThirdViewController *third = [[ThirdViewController alloc]init];
UINavigationController *nv = [[UINavigationController alloc]initWithRootViewController:third];
[self presentViewController:nv animated:YES completion:nil];
}
@end
###ThirdViewController.m
#import "ThirdViewController.h"
@interface ThirdViewController ()
@end
@implementation ThirdViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
self.title = @"サードビューコントローラーさん";
// Do any additional setup after loading the view.
}
@end