How to create multiple windows / views on iPhone?

Is it possible to create multiple views or windows in a Windows-based iPhone application?

+7
ios objective-c iphone cocoa-touch
source share
2 answers

Yes it is possible. Just create a new view using the view controller and instantiate this view in your class. Then in ibaction you can do some deletions and add subviews. This is just a quick and easy way, you can get more detailed information about how you will manage each view, etc.

Edit by query: In your class, you must create an instance of this interface in this interface:

MyClass *myClass; (make sure to alloc and init in the init or awakeFromNib method) 

Then create an instance of the application delegate in ibaction as follows:

 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]; 
+2
source share

You can do something like the following to add a view programmatically:

  //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 view as a subview of the window UIView *controllersView = [viewController view]; [window addSubview:controllersView]; [window makeKeyAndVisible]; 
+1
source share

All Articles