views:

11

answers:

0

Case 1:

I have created View-based sample application and tried execute below code. When I press on "Job List" button it should load another view having "Back Btn" on it.

In test function, if I use

[self.navigationController pushViewController:jbc animated:YES];

nothing gets loaded,

but if I use

[self presentModalViewController:jbc animated:YES];

it loads another view haveing "Back Btn" on it.

Case 2:

I did create another Navigation Based Applicaton and used

[self.navigationController pushViewController:jbc animated:YES];

it worked as I wanted.

Can someone please explain why it was not working in Case 1. Does it has something to do with type of project that is selected?

@interface MWViewController : UIViewController {

}

-(void) test;

@end

@interface JobViewCtrl : UIViewController {

}

@end

@implementation MWViewController

  • (void)viewDidLoad {

    UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    btn.frame = CGRectMake(80, 170, 150, 35);

    [btn setTitle:@"Job List!" forState:UIControlStateNormal];

    [btn addTarget:self action:@selector(test)

              forControlEvents:UIControlEventTouchUpInside];
    
    
    [self.view addSubview:btn];
    
    
     [super viewDidLoad];
    

}

-(void) test

{

JobViewCtrl* jbc = [[JobViewCtrl alloc] init];

[self.navigationController pushViewController:jbc animated:YES]; //[self presentModalViewController:jbc animated:YES];

     [jbc release];

}

  • (void)dealloc {

    [super dealloc];

}

@end

@implementation JobViewCtrl

-(void) loadView

{

self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

self.view.backgroundColor = [UIColor grayColor];

UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

btn.frame = CGRectMake(80, 170, 150, 35);

[btn setTitle:@"Back Btn!" forState:UIControlStateNormal];

[self.view addSubview:btn];

}

@end