Friday, April 8, 2011

Multiple Window/ view in a Window based app in iphone!

Is it possible to create multiple view or window in a (Window based) iPhone app ? If possible Plz tell me.

From stackoverflow
  • 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];
    
    Nahid : thanks for ur answer. can u give me some example or sample code?
  • In the Xcode documentation there's a book called "View Controller Programming Guide for iPhone OS" - that will help you.

  • You can do sth like that to add 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];
    

0 comments:

Post a Comment