Loading Views dynamically
Posted
by Dann
on Stack Overflow
See other posts from Stack Overflow
or by Dann
Published on 2010-04-07T22:10:42Z
Indexed on
2010/04/07
22:13 UTC
Read the original article
Hit count: 266
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
© Stack Overflow or respective owner