Container View or UIViewController for tableView with SubView - ios

I have a UIViewController in storyboard that will be a sliding up menu. I want to place it in a UITableView. If I place it as subview of UITableView and prevent it from scrolling, it gets the look I want, with one problem, the section headers of tableview scroll above subview.
Now, in order to prevent this behavior, I could reduce tableview frame, but it doesn't work because my subview is inside that same frame, right?
So , if that is true, what is the best way to achieve this? Place both screens inside a third UIViewController?

Don't try to put other views inside a table view. Bad news.
If your table view is managed by a UITableViewController then that's really all you can have in the table view (unless your views are inside cells, or in headers or footers.)
If you ARE using table view controllers to manage your table view(s), I suggest you create a container view on the view controller that needs to contain the table view, then control-drag an embed segue to the table view controller. That way the table view controller becomes a child view controller of the main VC, and you can put other view elements on the screen to your heart's content.

Related

Scrolling through Table View with embedded Table View Inside a Container View

This is a tableView. The white sections are the tableview cells. In the footer of tableView, I've added a scrollview with 2 containers views embeded with 2 UIViewControllers. These embeded view controllers contains tableView.
Now I'm having a problem with the scrolling. I'm scrolling the main tableview and as I scroll, I'm changing the height of the table footerview on which the scrollview is added. Now the problem is when I scroll through child view controller, I'm not able to scroll to the top of my main tableView. How should I do it? Is there is demo github project which I can refer to any code?
EDIT:
This is how my storyboard looks like:
I want to implement something like Facebook has implemented. I think they are using tableview with page view controller. How can I achieve this?

How can you make UITableView a subview of UIView retrospectively?

I have a view controller (subclass of UIViewController, not UITableViewController), with a table view as a subview. I now want to put another view on that screen, but can't resize the table view to not take up the entire screen, or drag in a view above that. It seems that the view can only contain a single table view. I know it's possible to have a table view and other views within the same screen, so what am i missing here?
Take a look at your view hierarchy on left - your view is subview of tableView. And you need to have something like
ViewController.view
|--> view
|--> tableView
And you have
ViewController.tableView
|--> view
Edit
What should you do
Copy (Cmd-C) your Table view. Than delete it
Drag View to your View Controller
Choose View and paste Table view to it (Cmd-V)
Drag View from Table view upwards to root view of Controller
Now, you can position your view and table view however you want

Adding a fixed-position view on top of a view

I have a UITableViewController inside a UINavigationController. I'm adding a "modal" subview to the tableView, which is a custom UIView when one of the rows is selected.
(It’s modal in spirit, not in the UIKit sense, since Apple doesn’t support modal views on iPhone, I’m adding it with a [self.view addSubview:customView] in my table view’s controller.)
I would like it to appear at the bottom of the screen and stay put there. I can get it to draw at the bottom, but once I scroll the table view, the view moves with it. Here are some illustrations:
Initial position (good):
Position after scrolling (bad):
I'm getting the bottom position by subtracting the height of all the chrome (navigation bar and status bar) as well as the height of the custom view from [UIScreen mainScreen].bounds.
How can I get the custom view to stay put? Should I constantly be adjusting its frame when the table view is being scrolled?
Your best and most flexible option is to switch to using a view controller with the table view as a subview so that you can change its frame and add sibling views. Then, when you want to add a modal you can run an animation to move the table view out of the way and slide the modal view in.
UITableViewController.view is an instance of UITableView. Means you added your custom view into a scroll view and that is why it scrolls. You can try to put your custom view into the tableFooterView property of the UITableView, which is the old school solution.
Personally I would create a container UIViewController and have UITableViewController be a sub viewController of it. Another sub viewController UIViewController or just a simple UIView could represent the footer.

Embed UITableView in Scrollview

I know Apple don't recommend to Embed UITableView in UIScrollview.
So this is what I am trying to do:
I have a registration form with fields embedded in UIScrollview,
for some fields I create a drop menu by presenting UITableView, the problem is when the UITableView appears with my object the didSelectRowAtIndexPath not responding.
If there is another way it I will happy to hear, if not how can I fix it in the Current situation , thanks.
Don't add the table as a subview of the scroll view, add it as a subview of the superview of the scroll view (and, consider adding it into a container view which detects touches outside the table to dismiss it from the screen without any selection being made).
If your 'root' view for the controller is the scroll view, change your view hierarchy to use a plain view as the root and have the scroll view as a subview of that.
You may also want to use bringSubviewToFront: to ensure that the presentation is correct.

Embedding a UIContainerView as a portion of screen in a UIViewController

I have a screen in my storyboard where I would like to embed a container view into a portion of the screen. I can't figure out if I should add a new containerview or view from the object library and then drag in a collection view controller or collection view (or tackle it a different way?). I've tried all combinations but just end up with the embedded view being shown black even if I drag collection view cells and set a background colour to test it. Once I can get this working I plan to populate the cells from an external database.
Any suggestions please? I'm doing this using storyboard as far as possible.
Thank you.
After you drag a container view into your view, you automatically get an embedded view controller, whose size is matched to the container view's size. You should delete that controller, and drag in a UICollectionViewController. Control drag from the container view to this controller and choose embed when you let go -- this will resize the collection view controller. You can give the collection view a background color, so you will see where it is, but giving the cells a background color won't show up until you implement the methods in the controller to populate those cells.

Resources