Pinned subview of a popover controller having a tableview inside - ios

I am trying to add a hovering subview to a UIPopoverController. I have a table view controller as a content view controller inside the popover. I tried to add it as a normal subview:
UIPopoverController* popoverController = [[UIPopoverController alloc] initWithContentViewController:myTableViewController];
UIView* mySubview = ...
[popoverController.contentViewController.view addSubview:mySubView];
It is displayed correctly but unfortunately scrolls up and down with the table view. I would like to have its position fixed.
I also tried to update the position of the subview by the y offset of the scrollview in the scrollViewDidScroll: method of the table view controller, but would like to avoid this solution if possible.

You have to make the content controller a UIViewController subclass rather than a UITableViewController subclass.

Related

iOS:How to add a view on searchBar in UISearchDisplayController and I want the view on top of _UISearchDisplayControllerDimmingView

How to add a view on searchBar in UISearchDisplayController and I want the view on top of _UISearchDisplayControllerDimmingView?
I add the view by [self.searchDisplayController.searchBar insertSubview:view3 atIndex:0];. But it was under _UISearchDisplayControllerDimmingView.
I show U the pic:
If someway to dismiss the _UISearchDisplayControllerDimmingView will help me also!
If you really want it on the top of dimView put your view on the window of Application.
UIView *view = [[[UIApplication sharedApplication]windows]objectAtIndex:0];
and add your view as subview.

uitableview inside multiple view controllers

I have to 'repeat' a uitableview into 2 or more view controllers. Like using a uitableviewcontroller with its methods inside view controllers using the methods/delegates/datasources from the uitablewviewcontroller.
Example: I've a uitableviewcontroller wich displays a twitter feed with its own style, so I need this table in more than 1 view controller and maybe just changing the twitteruser in each view controller (just an example).
TRY: What I've done is to create (with storyboard) a uiviewcontroller and a uitablewviewcontroller, both with their own methods. And on uiviewcontroller viewdidload, try to add the uitablewviewcontroller.tableview as a subclass. and this works! But the result is an empty table. I tried to set the delegates/datasources but it ddnt work..
-(void)viewDidLoad
{
[super viewDidLoad];
//Add Table as subview
thetable *t = [[thetable alloc] init];
[self.view addSubview:t.tableView];
t.tableView.frame = CGRectMake(0, 100, 320, 2000);
t.tableView.backgroundColor = [UIColor blueColor];
}
This code works, but just displays an empty uitable inside the view controller..
*thetable is a uitableviewcontroller object (.h, .m, and storyboard view)
*Just set the backgroundcolor to check if there's anything on screen
*using ios6
Thanks!
Make sure you are implementing the table view delegate and datasource methods in thetable.Also try [t.tableView reloadData] after adding the tableView to the view controller's view.

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....

Navigation controller with two views

I have a navigation controller that controls view switch. How can I show a view without removing the current view?
if your new view has a view controller use
[self.navigationController presentModalViewController:newController animated:YES];
This will add a view to the viewcontrollers view.
[parentView addSubview:subView];
This will add the view in variable subView into the view in variable parentView. In your case this would mean parentView is the viewcontroller's view and the subView is the view you want to add.
You can change the position of the subView in the parentView by setting the subview's subview.frame property.
If you are talking about a viewController you want to show take a look at the answer of Andiih.

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.

Resources