Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a multiple windows/views on the iPhone?

Is it possible to create multiple view or window in a (Window based) iPhone app?

like image 417
Md Nasir Uddin Avatar asked Feb 24 '09 09:02

Md Nasir Uddin


People also ask

Can you have multiple windows open on iPhone?

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.


2 Answers

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];
like image 148
simplyharsh Avatar answered Oct 17 '22 13:10

simplyharsh


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];
like image 21
Robert Childan Avatar answered Oct 17 '22 13:10

Robert Childan