Is it possible to create multiple view or window in a (Window based) iPhone app?
In addition to app switching, multitasking can enable different experiences on different devices. On iPhone, multitasking lets people use FaceTime or watch a video in Picture in Picture while they also use a different app.
Yes kind of possible. Just create a new view using a view controller and create an instance of that view in your class. Then in an ibaction you could do some removing and adding subviews. That's just a quick and easy way tho, you can get into a lot more detail with how you would manage each view, etc.
Edit on Request: In your class, you would create an instance of it in the interface like so:
MyClass *myClass; (make sure to alloc and init in the init or awakeFromNib method)
Then make an instance of the app delegate in the ibaction like this:
MyAppDelegate *myAppDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
And then you can do this to switch from one view to another:
[self removeFromSuperView]; (or self.view in case this is a view controller)
[[myAppDelegate window] addSubview:myClass];
You can do something like the following to add a view programatically:
//If you create controllers via XCode, just link them in the .h file with IBOutlet
UIViewController *aViewController = [[UIViewController alloc] initWithNibName:@"YourNibName" bundle:[NSBundle mainBundle]];
self.viewController = aViewController;
[aViewController release];
// Add the view controller's view as a subview of the window
UIView *controllersView = [viewController view];
[window addSubview:controllersView];
[window makeKeyAndVisible];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With