I'm making a newsstand app and I need multiple components in a single view. I have a UIViewController
that displays and manages a pdf (zooming, scrolling,etc...) but I don't want it to be full screen instead I want it to be like an UIView
inside another UIViewController
which has a menu on top, page numbering on the bottom and other tools. Both are subclass of UIViewController
... I already have both working separately. I just want the pdf viewer inside the other. Is it possible? here's some code of what I want (lets say is inside the viewDidLoad
)... but obviously doesn't work. Any help is appreciated. It also must be IOS 5.1.1 compatible and above
NSString *path = [[NSBundle mainBundle] pathForResource:@"myPdf" ofType:@"pdf"];
PDFViewController *page = [[PDFViewController alloc] initWithPDFAtPath:path];
//pdfView is a UIView of size 600x600 right in the middle
[self setPdfView:[page view]]; //this doest work... but it's basically what I want instead of presenting a viewController
//[self presentViewController:page animated:YES completion:NULL];
I'm also aware of this, but I don't understand... if this is the way I would like some guidance:
addChildViewController:
willMoveToParentViewController:
didMoveToParentViewController:
They are separate classes: UIView is a class that represents the screen of the device of everything that is visible to the viewer, while UIViewController is a class that controls an instance of UIView, and handles all of the logic and code behind that view.
The UIViewController class defines the shared behavior that's common to all view controllers. You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.
init method does not invoke the loadView method. This one is invoked the very first time the ViewController is asked to show its view to the screen. If the VC is presented and the view has never been loaded before, the loadView method is invoked.
As of iOS 5 you can do View Controller Containment which lets you add child view controllers into a parent view controller. The child view controllers can manage all the logic like they normally would but the view of the child controller can match any frame/position you like.
To add the controller you can do
[self addChildViewController:childViewController];
childViewController.view.frame = [self frameForChildController];
[self.view addSubview:childViewController.view];
[childViewController didMoveToParentViewController:self];
You can learn more about it in the View Controller Documentation
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