Search code examples
iphoneiosviewcontrollersubview

IOS - Load a sub-controller/view into a View


I'm working on an iPad app (actually, converting a iPhone app into iPad app). Since I can put two "Iphone screens" on one "iPad screen" (just regarding the space), I have my iPad view 50% occupied by my original view (loaded through my main controller).

(so far so good)

Now, on the remaining 50% of the iPad view, I want to include another View (for which I have a controller and a view, iphone-sized). I tried to add a "View" component, but how do I load another controller into it ? is that even possible ?

  1. MainViewController loading MyView1.xib
  2. I want to load, in the "View" component, MySecondaryController, loading MyView2.xib

Schéma http://imageshack.us/photo/my-images/835/d8fs.png/

Thanks


Solution

  • you can do it something like below...write below code in function which is in Mainviewcontroller(for example on some button tap)

    yoursecondviewcontroller *objDate = [[yoursecondviewcontroller alloc] initWithNibName:@"yoursecondviewcontroller" bundle:nil];
        objDate.delegate = self;
     UIPopoverController *datePopOver = [[UIPopoverController alloc] initWithContentViewController:objDate];
        datePopOver.delegate = self;
        [datePopOver setPopoverContentSize:CGSizeMake(320,393)];//give any size you want.
        [datePopOver presentPopoverFromRect:CGRectMake(50,700, 320, 393) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];//give size and origin whatever you want in FromRect .....
    

    You can also define UIPopoverController object in .h file....

    and don't forget to set delegate of UIPopoverController that is UIPopoverControllerDelegate

    Let me know it is working or not!!!

    Happy Coding!!!!