iOS: How to add toolbar or any footer below Table View? - ios

I've followed the CS193p introduction course to objective C. I have now a grouped Table View, and my view controller is a CoreDataTableViewController (from the CS193p class), which is basically just a subclass of UITableViewController with the FetchedResultsControllerDelegate implemented. In my app there are several screens connected, so if you press one row in the first table you get to a new screen with all the subcategories for that main category etc. All the screens are subclasses of this CoreDataViewController.
I'm now confused about how to add a toolbar at the very bottom of a screen in one particular Table View. I guess I have to insert a new view in which I include a table view and a toolbar. What I don't understand how to hookup everything so the whole TableView actually works? Before the very "top" controller was my CoreDataTableViewController (which I've subclassed and implemented my own methods), but now I have no idea how to continue? How do I get the values from the parent view controller to this embedded table view controller and further to his child view controller later on?

If you have a navigation based application you can set up a toolbar by calling:
[self.navigationController setToolbarHidden:NO];

Related

Xcode Storyboard: Can't add View to ViewController

I'm using Xcode 10 (with Swift 5 and for iOS 12) and my app is currently set up like this:
UIViewController 1 (login screen) - segue12 to ->
NavigationController that automatically created
UIViewController 2 with a UITableView - segue23 to ->
UIViewController 3 (detailed info about an item in the UITableView with automatically created "back" button)
The NavigationBar only contains a " ".
I now want to add another UIView with a button below the UITableView but Xcode won't let me drag it below the UITableView, only either into the UITableView or directly underneath "First Responder", which puts the View outside into its own window.
If I delete "My Table View", it won't let me drag in a replacement either.
How do I fix this, so I can add the new UIView + UIButton?
NavigationController that automatically created UIViewController 2
That explains everything. When you drag a navigation controller into the storyboard, what you get is a navigation controller and its root view controller, and the root view controller is a UITableViewController.
Let's step back for a moment. A view controller can and must have exactly one main view. It occupies the whole scene. It cannot be resized. It cannot have a sibling view, because it has no superview for a sibling view to be a child of. It can only have children (subviews).
Well, in this case, ViewController2 is a UITableViewController, and MyTableView is ViewController2’s main view. (A table view controller is always configured this way, and that is what you got when you dragged the navigation controller into the storyboard.) That is why you cannot add more views to it, except as subviews, e.g. prototype cell contents. Your button has no place to go except inside the table view.
So, what to do?
If the extra interface you want to add is just a button, the usual solution is to put it into the navigation bar. It becomes part of the table view controller's navigation item.
If you don't want to do that — that is, if you really want the button and the table view to be siblings of one another in the interface — then you need to replace ViewController2 itself with an ordinary view controller. Now its main view will be an ordinary view, and you can drag anything you like into it, including a table view and a button. More likely, instead of a bare table view, you would use a container view, with an embed segue to a table view controller.

Putting a navigation controller with hierarchical table views inside of a view controller in swift

I am making an iPad application which requires the use of a "drill down" style set of table views for users to add elements to a list (i.e. a user taps on a table view cell and it brings up more detail or options, like you would see in settings). My problem is that I need to be able to place this table view inside of a view controller amongst other content. I can add a table view, but I need the navigation bar at the top of the view in order to mimic a tableView inside of a navigation controller.
You need to use a UIViewController and
give it a tableView property
make it conform to the UITableViewDataSource protocol
make it conform to the UITableViewDelegate protocol
Navigation controller works exactly the same way regardless if you use a UITableViewController or UIViewController. Create storyboard segues and inform the detail view about the object to be displayed in prepareForSegue.

Adding TableViews to TabBarView & how to customise prototype cell

Im building my iphone application and this is how my storyboard looks right now.
First question: Adding another table view
My first two tab bar items are going to contain table views. Now as you can see i have my first table view connected and all, how would i do to get the empty view under Navigation Controller to be a a Table View. Would i need to add another Navigation controller? or how does it work cause i have never worked with tabbars/tableviews before.
Second question: Customize prototype cell
My first Table View can show the data that i inputed as you will see in the following picture. The first picture is how its currently being shown. How can i make a custom prototype cell that would look like the second picture?
Please not that the cells will be very much alike each other in both of my table views. I will have an if statement where i will check a specific thing and if its true it will hide for example the image but all the other things would be the same so would i make a class for the cells?
For better solving your questions, You must first understand the purpose of Navigation Controller. Navigation Controller is there for you to push and pop between controllers, which is convenient when you have levels of data. It manages a stack of controllers. You don't always need a navigation controller to work with tableview. However, it's a common practice to put Navigation controller and TableView (with view controller or solely UITableViewController) together for easy showing levels of data.
Basically, there are two ways to add a TableView. You can directly drag a table view onto your empty view controller or delete the empty VC, then drag a UITableViewController. Most importantly, select the whole VC and go to Editor (at the top) choose embed in a Navigation Controller.
Link about navigation controller from Apple's document
Since you use storyboard, you can directly customize your tableViewcell in storyboard. You already have a prototype cell. You can now directly drag UIImage or Label on that. Most importantly, create a class subclassing UITableViewCell and connect objects in your tableViewCell as an IBOutlet so that you can control it. If you feel plain text explanation is not enough, I find a tutorial for you.
You could refer to the link section Prototype Cells.
1) Yes you will need a 2nd navigation controller for each tab.
Delete the UIViewController.
Drag a UITableViewController to the storyboard.
Embed the UITableViewController in a NavigationController.
Set a segue from the tab bar button to the new NavigationController.
2)
To fully set up the prototype cell you showed you will need to create a new class which subclasses UITableViewCell and then set IBOutlets for all the labels etc.

Segmented control on top of a table view, not in the title view though

How can I put a segmented control on top of a tableview. I don't want it on the title view of the navigation controller and I don't want it to scroll with the tableview either. For reference of what I mean, please look at App Store app, choose Categories, then select any category. There you will see the segmented control I'm looking for. The one with 'Paid', 'Free', and 'Release Date' segments. I'm using the code not IB, so if you know how please answer this with code not IB drag and drop.
When you need other components in a table view controller other than the table view, you can't use a UITableViewController. You need to use a UIViewController. You add the UITableView as a subview and you make the view controller the table view's data source and delegate. Then you can add any other components to the view controller's view as well. This way the additional components don't scroll with the table view. There's a little more plumbing to do to get the view controller to behave exactly like a table view controller. This includes overriding the setEditing:animated: method to set the editing property of the table view. It includes deselecting any currently selected row in the viewWillAppear: method.
UITableViewController has the table view as its view. This prevents you from adding any other subview to the table view controller in a way that they won't scroll.

TableView as subview with navigation controller

I would like to have a view (one of five tabbars) with some subviews (labels, images and such) including a table view, so that the table view will only take up half of the screen (similar to this thread Add tableview as subview to view?). I have set up the views controller as tableview delegate and data source, but how can I use navigation with this table view (uinavigationcontroller)?
Clarification:
I started out with a tab bar based app, and wanted to have one of the tab bar views to have some labels in to top and a table view in the lower half of that view. I solved it myself, see below
This was of course simpler than I thought it was. I set up a tab bar controller with some tabs (with individual view controllers). I embedded one of the view controllers in a navigation controller (using the menu Editor -- Embed in -- Navigation Controller). Added the labels and a uitableview (through Storyboard) to the view and hooked up outlets for the labels and the table view, as well as setting the view controller as delegate and data source (UITableViewDelegate, UITableViewDataSource).

Resources