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
Related
I want to have a Table View that occupies the top 5/6ths or so of the screen, and then have a View that occupies the bottom 1/6th of the screen. Xcode won't let me simply drag a View into the Table View (as I already have a static view at the top of the Table View. I'm not really sure why it won't let me do a second one at the bottom...) so I'm setting it up as two separate views located on a single screen. What type of view should I embed the Table View and View in? A Container View? A plain old View? Thanks!
Purpose: I'm trying to create a static View that always stays at the bottom of a Table so I'm setting it up as a separate View below the Table View. Unless there's a better way to get a static View to show up at the bottom of a Table View in addition to the static View I already have at the top of the Table View? I don't want this bottom View to scroll with the Table.
I was trying to build home base application which mean there are many icon at root view and it will navigate to appropriate view. So, I will use collection view for it. But, the problem is when I add button to the collection view, the button didn't scroll with collection view, when I scroll collection view up. Here is my simulator build:
As you can see,the button "Click here to login" didn't scroll up with collection view. So, is there any way that I can add button to center of collection view which will scroll with collection view?
Here is my storyboard :
What am I doing wrong?
When you take a closer look at your view hierarchy in Interface Builder you'll notice that the button you added isn't actually a subview of your collection view. I added a red line to indicate which objects belong to the collection view.
Your login button is on the same level as your collection view in the view hierarchy. Both are subviews of your view controller's root view. So no wonder the button doesn't scroll with the collection view.
However, you cannot simply add an arbitrary view (or button) to the collection view itself in Interface Builder. You'll need to add a Collection Reusable View first as your collection view header and then add your button to it.
Your storyboard scene in Interface Builder will then look like this:
Please note that you'll also need to add some code to your collection view data source (which will probably be the same as your collection view controller) in order to make this work.
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.
I have created a table view controller with a table view cell for my iOS app with storyboard in Xcode 6. In the cell I have an image and a label. At the top of the view controller I want to have a header and at the bottom I have a tab bar. That's my setup.
But now I want to change the position and the layout of the table view and the inherit cells, default they cover the whole screen. The table view should start below the header and should end above the tab bar. At the moment the cell content is displayed under the headline and the tab bar. Is it possible to set the positions of the table view and/or cell? And also I want to change the layout of the cells. I want to have some space between two cells and a corner radius.
THX!
This is an old "problem". If you want to use a UITableViewController, the table view will cover the whole screen. In fact the UIViewController's view property will be the table view.
If you want to have a table view and other views on the screen, you will have to use UIViewController and add two subviews to it's view: the header and the table view.
Do the following (which the UITableViewController would have done for you):
add the table view as an ivar;
have the class conform to UITableViewDelegate and UITableViewDataSource and
set it to the table view's delegate and datasource
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.