UITableViewController, Storyboards and UIKeyboard - ios

I am trying to create a UI just like Facebook's comment screen on mobile.
I got a UITableViewController on my storyboard. I need to insert a view docked to the bottom of the screen to place a text field. Since the tableview is taking the full screen, I can't do it on storyboard and I think I need to do it programmatically but how? Should I modify the constraints that stretch the tableview to the edges and insert the views or what?
Thanks.

You can always add table view to normal UIViewController and below it add another view.

Related

Adding a Subview on top of a Table View Controller in a specific location of the screen

I have a TableViewController and would like to have a button over top of it in the bottom right corner, about 50x50 for size. I think the best way to do it is to load the button as a subview over the main TableViewController. But I can't figure out a way to do it.
How do I properly configure the xib file, the swift file to go with the xib, and then how to I create and locate the subview in my TableViewController.swift?
The best approach is probably to create a ViewController with your button and a TableView as subviews.

keep keyboard from hiding UITextField at bottom of UITableView

According to the answer at UITableView, make footer stay at bottom of screen?, which I verify:
In order to have a footer that stays put at the bottom of the screen,
and doesn't scroll with the table, then you can't use a table view
footer. You can't even use a UITableViewController, you'll need to
implement your view controller as a UIViewController. Then you add
your own table view as a subview. You'll also need to add your footer
as a subview of the view controller's view, not the table view. Make
sure you size the table view so its bottom is at the top of the footer
view.
but the problem is that my UITextField, inside my footer, is being hidden by the keyboard when user tries to type. So how do I keep the keyboard from hiding the UITextField? Throughout the app, I have been using TPKeyboardAvoiding. But in this case, where a UIScrollView/TPKeyboardAvoidingScrollView contains a UITableView and a UIView in vertical order, it does not work. I generally like TPKeyboardAvoiding because it’s so quick and easy. Any ideas how I might fix this issue?
The instruction that you quote is telling you to use a UIViewController, add a UITableView as a subview, then add a UITextField as a subview of the UIViewController NOT as a subview of the UITableView.
Let me draw it out for you:
Step 1:
Add a UITableView to your view controller
Step 2:
Add your UITextField subview (you can embed the UITextField in a UIView container if you like) as a subview of your UIViewController's view NOT your UITableView footer.
Step 3:
If depending on if your using frames or autolayout, you adjust the frame or autolayout constraint constant values for your UITextField subview when user tap on the text field.
Step 4:
Finally, the keyboard appears and the UITextField doesn't get obscured by the keyboard.
Just make sure your UITableView doesn't initialize it's own automatic scrolling for keyboard appearing. If you use UITableViewController then just subclass it and make sure you don't call it's viewWillAppear:. I didn't investigate which exactly method you should block without using UITableViewController, so, you should find out this yourself or somebody else would help.
I did similar in my own project where I wanted to have own scrolling of table view for keyboard appearing.

iOS Autolayout - black screen when adding view above table view

I have UIViewController with UITableView which fill entire screen (I am using auto layout). When I add some view to the view above table view sometimes when I push to this view controller I see black screen, but only in the place where should be table view. Sometimes when I remove the view and add other then works sometimes not. So I have no idea why sometimes works sometimes not and what can cause thsi error. I can even add only IBOutlet to the one of the constraints and then I see black screen, if I then delete the view with this constraint, then works and if I then click undo and the view comes again, then works. I don't undernstand it.
Can someone help me?
The default tableview background colour is black so it may be that you're table isn't being populated. Try setting the bg colour of the table view to something obvious (e.g. red) and also check your datasource is available when the table is trying to layout.
Sorry, it was my error I didn't notice. I set view of my view controller to tablew view in the interface builder.

UICollectionView as subview of UIViewController

I want to use a collection view thats horizontally scrollable along the bottom 25% of my screen full of pictures and then use the top 75% of the screen to display information about the selected cell (zoomed in picture, caption, people in it, etc.) of the collection view. My question is how to go about implementing view controllers in this situation.
Will I need a UIViewController to handle the whole screen and UICollectionViewController to handle the collection view (how do I get them to work together?) Or could I implement the whole screen with just one view controller? (if so, which one?) Should I use a custom CollectionViewController with one section being my main info, and another section being the bottom scrollable part?
No, just have one UIViewController and add the UICollectionView as a subview. Then set the dataSource and delegate and tell it to reloadData. If it seems too easy, you're overthinking it.

Adding subviews on a UITableView

I'm working on a project were I use mostly UITableViews. The user enters data and the App gives the result of a calculation. I have two buttons: "Calculate" and "Reset". I want to add a subview containing these two buttons and have them displayed at the bottom of the screen. By Storyboards, I can add the subview, but it sticks to the button of the UITableView, not the screen.
Any idea on how to accomplish that? Should I mess with the constrains between the subview with the buttons and self.tableview.superview ?
Any help is appreciated!
You can use a standard UIViewController instead of a UITableViewController, and add a UITableView to your view controller. You can then place subviews at will.
Do not forget to connect datasource and delegate of your tableview.

Resources