Open judaco opened 7 years ago
//
// ViewController2.m
// View Controller
//
// Created by hackeru on 19/04/2017.
// Copyright © 2017 juda. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ViewController2.h"
@implementation ViewController2
{
UILabel * label;
UIButton * button;
}
-(void)viewDidLoad{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blueColor];
label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
label.center = CGPointMake(self.view.center.x, 100);
[label setText:@"View Controller 1"];
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(0, 0, 100, 30);
button.center = self.view.center;
[button setTitle:@"close" forState:UIControlStateNormal];
[button addTarget:self action:NSSelectorFromString(@"buttonClick:") forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void)buttonClick:(UIButton *) sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
//
// ViewController.m
// Inner View Controllers
//
// Created by hackeru on 19/04/2017.
// Copyright © 2017 juda. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ViewController.h"
#import "ViewController2.h"
@interface ViewController ()
@end
@implementation ViewController
{
UILabel * label;
UIButton * btnGoTo2;
UIButton * btnGoTo3;
ViewController2 * controller2;
}
- (void)viewDidLoad {
[super viewDidLoad];
label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,200,30)];
label.center = CGPointMake(self.view.center.x, 100);
label.text = @"First Screen";
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
btnGoTo2 = [UIButton buttonWithType:UIButtonTypeSystem];
btnGoTo2.frame = CGRectMake((self.view.frame.size.width-150*2-10)/2, label.frame.origin.y + 200, 150, 30);
[btnGoTo2 setTitle:@"Second Screen" forState:UIControlStateNormal];
[btnGoTo2 addTarget:self action:NSSelectorFromString(@"btnGoTo2:") forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnGoTo2];
btnGoTo3 = [UIButton buttonWithType:UIButtonTypeSystem];
btnGoTo3.frame = CGRectMake(btnGoTo2.frame.origin.x + btnGoTo2.frame.size.width + 10, label.frame.origin.y + 200, 150, 30);
[btnGoTo3 setTitle:@"Third Screen" forState:UIControlStateNormal];
[btnGoTo3 addTarget:self action:NSSelectorFromString(@"btnGoTo3:") forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnGoTo3];
}
-(void) goToViewController:(int)which{
if (controller2 == nil)
controller2 = [[ViewController2 alloc] init];
controller2.shouldGoTo = 2;
[self presentViewController:controller2 animated:YES completion:nil];
}
-(void)btnGoTo2:(UIButton*) sender{
[self goToViewController:2];
}
-(void)btnGoTo3:(UIButton*) sender{
[self goToViewController:3];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
//
// ViewController2.h
// Inner View Controllers
//
// Created by hackeru on 19/04/2017.
// Copyright © 2017 juda. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController2 : UIViewController
@property int shouldGoTo;
@end
//
// ViewController2.m
// Inner View Controllers
//
// Created by hackeru on 19/04/2017.
// Copyright © 2017 juda. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ViewController.h"
#import "ViewController2.h"
#import "ViewController3.h"
@implementation ViewController2
{
UILabel * label;
UIButton * btnGoTo1;
UIButton * btnGoTo3;
ViewController3 * controller3;
}
@synthesize shouldGoTo;
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor greenColor]];
label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,200,30)];
label.center = CGPointMake(self.view.center.x, 100);
label.text = @"Second Screen";
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
btnGoTo1 = [UIButton buttonWithType:UIButtonTypeSystem];
btnGoTo1.frame = CGRectMake((self.view.frame.size.width-150*2-10)/2, label.frame.origin.y + 200, 150, 30);
[btnGoTo1 setTitle:@"First Screen" forState:UIControlStateNormal];
[btnGoTo1 addTarget:self action:NSSelectorFromString(@"btnGoTo1:") forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnGoTo1];
btnGoTo3 = [UIButton buttonWithType:UIButtonTypeSystem];
btnGoTo3.frame = CGRectMake(btnGoTo1.frame.origin.x + btnGoTo1.frame.size.width + 10, label.frame.origin.y + 200, 150, 30);
[btnGoTo3 setTitle:@"Third Screen" forState:UIControlStateNormal];
[btnGoTo3 addTarget:self action:NSSelectorFromString(@"btnGoTo3:") forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnGoTo3];
NSLog(@"in viewDidLoad of 2 %i", shouldGoTo);
}
-(void) goToViewController:(int)which{
if (controller3 == nil)
controller3 = [[ViewController3 alloc] init];
controller3.shouldGoTo = 3;
[self presentViewController:controller3 animated:YES completion:nil];
}
-(void)btnGoTo1:(UIButton*) sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)btnGoTo3:(UIButton*) sender{
[self goToViewController:3];
}
-(void)goTo3{
if (controller3 == nil) {
controller3 = [[ViewController3 alloc] init];
[self presentViewController:controller3 animated:YES completion:nil];
}
}
-(void)viewDidAppear:(BOOL)animated{
NSLog(@"in viewDidAppear of 2 %i", shouldGoTo);
if (shouldGoTo == 1) {
[self dismissViewControllerAnimated:YES completion:nil];
}else if (shouldGoTo == 3){
[self goTo3];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
//
// ViewController3.h
// Inner View Controllers
//
// Created by hackeru on 19/04/2017.
// Copyright © 2017 juda. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController3 : UIViewController
@property int shouldGoTo;
@end
//
// ViewController3.m
// Inner View Controllers
//
// Created by hackeru on 19/04/2017.
// Copyright © 2017 juda. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ViewController3.h"
@implementation ViewController3
@synthesize shouldGoTo;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end