I do not use the tab bar or any other control - I want to basically change the current view to another view controller dynamically (i.e. through code). I don't use Interface Builder at all ...
For example, suppose we create three view controllers:
(this may not be the best example, but I'm trying to make it simplified)
View_Hello.m (and .h)
View_Goodbye.m (and .h)
View_Ciao.m (and .h)
Our ViewerAppDelegate will launch View01_Hello.
View_Hello will have a custom touch method, which would then have to go to View_Ciao if it was skipped, but View_Goodbye if it just touched.
Any ideas on how I can do this (and please donโt say โoh, you need to use the xxx interface element for this example.โ I need to be able to randomly change the views based on program control in the view of the application over which I I work)
I surf through Google and StackOverflow last week and went through my three O'Reilly Cocoa books (plus three books for the iPhone developers), and they all just use simple interfaces, but nothing shows an example like what I'm trying to do.
============
Edit (grant @Andrew):
eg:
View_Ciao *viewCiao;
-(void) viewDidLoad {
viewCiao = [[View_Ciao alloc] initWithNibName:@"View_Ciao" bundle:nil];
[viewCiao.view setNeedsDisplay];
[super viewDidLoad];
}
Failure. :-)
==============
Edit (@ Daniel Dickison)
Brilliant - it worked!
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
viewCiao = [[ViewCiao alloc] init];
[viewController.view removeFromSuperview];
[window addSubview:viewCiao.view];
}
source
share