UIPageViewController: how to add a non-paging toolbar or other "overlay" elements? - ios

I have implemented a PDF viewer. Currently it is a UIViewController that contains a UIPageViewController.
My toolbar, some overlay elements (like quick access to certain pages of the PDF) are added to the standard UIViewController's view.
However I wonder if that is required? Would it be somehow possible to inherit from UIPageViewController and have the paging effect for sub controllers and still have "floating" elements on top that won't be paged?
or is the containment the way to go?

We should create UIPageViewController programmatically and add its view to another UIViewController's view as a subview. And the elements that we want them to be 'overlay' should be subviews of the host UIViewController.
For example, in - viewDidLoad:
UIPageViewController *pvc = // init this on your own way
pvc.dataSource = // your data source
// Set page view controller's view's frame to match host view's frame
pvc.view.frame = self.view.bounds;
// And here comes the magic
[self.view insertSubView:pvc.view belowSubview:<any subview>];
Briefly we only use UIPageViewController's view but not itself.
Hope this helps.

Related

Add view behind tableview in UITableViewController

I'm trying to add this custom control below my tableview in a TableViewController:
https://github.com/zogieosagie/RMEIdeasPullToSortControl
In the example the creator gives, the control is implemented using a ViewController and an added tableview, but I want to use it in a TableViewController. I have created and initialized it as shown in the example but I cannot get it to show up behind the table. Any ideas?
Here is a screenshot of the control above my tableview: https://www.dropbox.com/s/ojfpacxelcy9cqm/Photo%20May%2028%2C%208%2057%2035%20PM.png
Here is my code in the viewDidLoad method:
[self.tableView setBackgroundColor:[UIColor clearColor]];
self.rmeideasPullDownControl = [[RMEIdeasPullDownControl alloc] initWithDataSource:self delegate:self clientScrollView:self.tableView];
self.sortTitlesArray = [[NSArray alloc] initWithObjects:#"Listed from A - Z", #"Listed from Z - A", #"Brand value: HIGHEST - LOWEST", #"Brand value: LOWEST - HIGHEST", #"Founded: OLDEST - NEWEST", #"Founded: NEWEST - OLDEST", nil];
CGRect originalFrame = self.rmeideasPullDownControl.frame;
self.rmeideasPullDownControl.frame = CGRectMake(0.0, 45.0, originalFrame.size.width, originalFrame.size.height);
//It is recommended that the control is placed behind the client scrollView. Remember to make its background transparent.
//[self.view insertSubview:self.rmeideasPullDownControl belowSubview:self.tableView];
[self.tableView addSubview:self.rmeideasPullDownControl];
[self.tableView sendSubviewToBack:self.rmeideasPullDownControl];
Table view controllers do not lend themselves to managing anything other than a table view. In a table view controller the content view of the view controller is the table view.
You should not try to add other views as subviews of a table view.
Those 2 things combined mean that you can't do what you are trying to do.
Instead, you should create a regular UIViewController. In your storyboard, add a container view to the view controller's content view. Create a UITableViewController as a separate scene, and then control-drag from the container view onto the table view controller. That will set up an embed segue, so your table view controller becomes a child view of the regular view controller. Now you can do whatever you want to the main view controller's content view, including adding other views behind the table view.
Do you mean that you are using a Table View Controller on the storyboard? Or do you mean that your backing code is a subclass of UITableViewController?
I haven't used this project before but I'm guessing you are using a Table View Controller on the storyboard, in which case there is no backing view for the RMEIdeasPulldownControl to attach to (the top-level view is a UITableViewController). If you look in the example it needs to be attached to a scrollview (like a table view) but it needs to be inserted into a view (like a UIView)
If you meant the second one then I'm not sure, UITableViewControllers are subclassed from UIViewControllers and are really very similar, so I can't imagine any trouble arising from that.
It isn't possible directly, but you can create UIViewControllerClass with relevant storyboard UIViewController
add a MyUIView in hierarchy then UITableView next to MyUIView
attach datasource and delegates for UITableView and use MyUIView as per your requirement.

popover content view doesn't display while viewcontroller has a child VC present

I have a container view controller that consists of a navigation view at top, and a content view for the remainder of the screen. The navigation menu consists of several buttons, some of which present a popover with UITableView for secondary navigation. This all worked until I assigned a child view controller and set it's view as subview of the content view. Now, the popover appears, but has nothing inside it (no tableview, just black).
Why is this?
Here's the code I added for the child vc in container view:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
ContentWebViewController *initialVC = [[ContentWebViewController alloc] init];
[self addChildViewController:initialVC];
initialVC.view.frame = self.view.bounds;
[self.containerView addSubview:initialVC.view];
self.currentController = initial;
}
See the screenshot below. I added a vc with a simple webview showing google (just as a placeholder for now). The popover was working fine before I assigned the child VC.
Maybe it will help other in other cases -
If you are using size classes (probably you are since you are developing this to iPad) -
Design your popover view controller in Any-Any size and it should be OK - after that you can return to your wanted size.
(You can also uninstall the size classes of any object in that view controller instead of redesign the VC)
I somehow (don't ask me how) changed the class that my table view controller was inheriting from. It should have been (obviously) UITableViewController, but was UITableViewController, so initWithStyle was not being called....

Adjusting a Child ViewController inside another viewController

I am trying out an application using a child ViewController inside another viewController.
I have a VC and I am instantiating another VC with its own xib inside the outer VC.
I am adding it as a child using the new iOS 5 method addChildViewController and also I have added its view as a subView.
But how do I control its position and size inside the parent view controller ?
should I modify the frame of the child controller's view ?
or I have to adjust the freeform view in the xib itself ?
Also in my current implementation, the child view starts behind the status bar of the parent viewcontroller's view.
Any idea on how to systematically implemement something like this ?
#define SUBVIEWS_FRAME CGRectMake(0,20,100,100) // whatever frame you need
- (void)addChildViewController:(UIViewController *)childController{
[childController.view setFrame:SUBVIEWS_FRAME];
[super addChildViewController:childController];
}
Simply just add a view in parentViewController #synthesize that view like childView. now add your childViewController as a subView in childView of parentViewController. it will simple to adjust using parentViewController View on nib file. If you have a large childViewController then please use UIScrollView instad of UIView

Insert image at top of UITableView when using UINavigationController?

I have a UINavigationController and UITableView in my MainWindow.xib. I'm trying to insert a non-touchable/non-movable image at the top of the view. (I don't want to simply change the UINavigationBar background, as from what I've experienced, the UINavigationBar height cannot be arbitrarily increased.)
As this is a root view, its behaviour is controlled by my RootViewController. When the view loads, I hide the navigation bar using self.navigationController.navigationBarHidden = YES;
I've tried adding a UIView to the top of the UITableView, but when the user scrolls through the table, the top image moves. How can I place a stationary image at the top of the UITableView without it moving as if it were a cell and without using a UINavigationBar background image?
Naively-Considered Possibilities:
Enclose the view in another view, the top of which contains the image?
Overlay an image mask at the top of the screen?
(HIG violation, anyone?)
If your view controller is a UITableViewController you can't easily add another view because the tableViewController just manages a single view which is the UITableView. I recommend using a plain UIViewController instead where you add a UIView for your top view and a UITableView for your content as subviews to the main viewController.view. Then, implement the UITableViewDelegate and UITableViewDataSource protocols in your UIViewController.
You can create another UIViewController which contains the UITableViewController and your static image on top. This way, you can even resize the table view so the static image is displayed above and not over your table.
UIViewController *middleViewController = [[UIViewController alloc] init];
[[middleViewController view] addSubview:tableView];
[[middleViewController view] addSubview:staticImageView];
...
[navigationController initWithRootViewController:middleViewController];
Has been a long time since I made my last cocoa application, so I cannot promise that it works.

Multiple UIViewControllers simultaneously

I would like to have a UITableView in a navigation controller occupying the entire screen. I have a smaller custom UIView which needs to slide up from the bottom, squeezing the table view by 100 pixels. The custom view needs to be static, not moving while the user navigates the tableview. Ive been told not to have 2 UIViewControllers (VC) managing views on the same screen.
Currently, my AppDelegate adds a subview to its window from a VC, which then loads the tableview and custom view with
[self addSubview:tablviewcontroller.view];
[self addSubview:customViewController.view];
How should this be implemented?
the way I would structure this is as follows:
have a UIViewController subclass whose view takes up the entire screen. It will have two subviews.
First subview: The view of the UINavigationController that contains your table view controller.
Second subview: the custom UIView.
Have the UINavigationController's frame initially be set to the entire bounds of the main view controller's view and the custom view's frame just below the visible area of the screen.
When you need to slide up the view, use UIView animation to animate changing the frame of the UINavigationController's view by decreasing the height and change the frame of the custom UIView by changing its y coordinate to now be in-frame.
Okay. You want a navigation controller, of which the root view is a table view. Then, possible by an user input, you want this table view to slide up by 100 pixels, and another view takes place at the bottom. While the other view stays there, the user may keep using the table view.
Here is how I would do it:
Create a generic view controller (let's call it NavigationWithAuxiliaryViewController). The root view of this class covers all your application window.
This view has an instance of UINavigationControlleras its property, say navController. It also has an UIView (for the other view) as its property (say, auxView). Position the other view at the bottom. However, this view is hidden by default. Also, the frame of the root view of UINavigationController covers the entire view.
When you decide to squeeze up the table view, modify frame property of UINavigationController. Do something like this (not this ugly though):
if (slideViewOn) {
[UIView beginAnimations:#"slideUp" context:nil];
navController.view.frame = CGRectMake(0, 0, 320, 260);
auxView.hidden = NO;
[UIView commitAnimations];
} else {
[UIView beginAnimations:#"slideDown" context:nil];
navController.view.frame = CGRectMake(0, 0, 320, 480);
auxView.hidden = YES;
[UIView commitAnimations];
}
The easiest way to squeeze up the whole navigation/table stuff is to modify the whole frame for the navigation controller, which is why you need a separate view (out of the navigation controller) for the other view.

Resources