iOS 중간에서 UINavagationController를 적용합니다. (Objective-C)

2691 단어 iOSObjective-C
타이틀 화면→천이→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

좋은 웹페이지 즐겨찾기