I have UITableView with Static cells. I control-drag from one of these static cells to another UINavigationcontroller and select "Push". I notice nothing happen, when I run the app and tap on the static cells.
However, when I do the same thing & choose "Modal" it works fine. Did I miss something?
You can only use a "Push" transition when segueing between view controllers within a parent UINavigationController.
Your Navigation Controller should be your app's initial view controller. Also when your table cell is tapped you'll want to segue to a View Controller (probably a custom UIViewController subclass), not a UINavigationController.
Make sure you have set your storyboard up with the following:
A UINavigationController - this should be set as the Initial View Controller for your app. Check that the checkbox "Is Initial View Controller" is checked in the Attributes inspector pane when the navigation controller is selected in the storyboard.
A UITableViewController - this should be set at your navigation controller's Root View Controller (there should be an arrow pointing from the nav controller to the tableview controller that looks like a segue but has a different icon in the middle)
Another View Controller - this is the view controller you want to segue to when clicking on your table cell, probably a customer UIVewController subclass you've created. Note that it should probably NOT be a navigation controller.
Related
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.
I have a tabBarController with 5 tabs the third tab is a navigation controller with TableViewController as the root view controller.
When I press on a row on the table view it push a detail view (regular view controller) about the selected row.
The problem is first time parentViewController and presentingViewcontroller properties (in the details page) are set, all other consecutive both properties are set to nil.
EDIT
I created a single tab application with navigation controller same as the one in the picture but I did not disable auto layout in the storyboard, every time parentViewController is set correctly.
I believe this is a bug if you disabled auto layout.
You are neither creating a child view controller, nor presenting a modal.
(Pushing a detail view controller onto a navigation controller's stack is kind of like adding a child, but navigation controllers predate the parent/child view controller mechanism, so they don't use it.)
What you need to check is the navigationController property of your detail view controller. That should be non-nil if it was pushed onto a navigation controller stack.
I have a ViewController, which is connected to a UINavigationController, that has two buttons, each one for a specific UITableViewController.
I drag and drop from each button to its corresponding UITableViewController and select show for the seque
the problem is that I can tap on the top of the first UITableViewController and set the name, but I can't do that on the second UITableViewController. my question is that normal?
please notice that the second UITableViewControlelr (Subtitle Cell Table View Controller) doesn't have a come back symbol like the other two do
as I am totally aware that I might need to wait because on swift still not a lot of programmers as in Android, i hope you help me
Updat3 1
I will add screenshot to show you my problem
this is the MainViewController
This is the first UITableViewController (as you see it has a title, which is players)
This is the second UITableViewController (my problem is here I couldn't add a title for it by clicking on the sense on my storyboard)
You need to drag a UINavigationItem into UITableViewController.
Navigation item belongs to a view controller and it is used to show the view controller title on the navigation bar. Every UIViewController has a Navitagtion item assigned to it. Its generated at runtime.
When a View Controller is pushed onto a Navigation Controller, the navigation controller gets the information for title view form the view controllers's Navigation Item.
So if you want to be able to change the title of a View Controller from storyboard, you need to add a Navigation Item in ViewController.
UINavigationController cannot have title changed, because, title belongs to ViewController, and navigation controller just show the relevant title onto its navigation bar.
I'm using storyboard to create an iPad app. On the main view I have a toolbar and a bar button item, let's call it "show". Then I have dragged a table view controller into the storyboard. I have also added a subclass of UITableViewController to the files and made the class of the dragged table view controller to be that subclass. And I made a popover segue from the "show" button to the table view controller. It works fine, meaning that when "show" pressed I see the popover showing the correct data that I set in the table view. What I cannot seem to figure out is how to put a toolbar on top of the table view in the popover. I took a step back and used a UIViewController instead of UITableViewController and still cannot add a toolbar by dragging it to the view. Any help will be appreciated.
I ended up putting the TableViewController within a NavigationController and the latter in a PopoverController, all in the code, without using IB. I found this an easier solution to get the toolbar than anything else that might work.
I'm creating a popoverSegue from a new view controller and want to push a third view controller onto the original stack. This is how I'm creating the application:
Create a new Single View Application
Select Use Storyboards
Select the MainStoryboard.storyboard file.
Select the only View Controller, change the Title and Identifier to initialView, then select Editor->Embed In->Navigation Controller
Drag two new View Controller objects from the Objects Library onto the canvas
Change the Title and Identifier of the new View Controllers to: popoverView and newView.
Add a Round Rect Button object from the Object Library to initialView and popoverView.
Add a Label object from the Object Library to `newView.
Control click the button in the initialView and drag to popoverView.
Select the Popover option from the Storyboard Segues menu that appears.
Control click the button in the popoverView and drag to the newView.
Select the Push option fromt the Storyboard Segues menu.
Build & Run.
Click the first button, and the popover appears, but when you click the button within the popover, nothing happens (it should push the new view but doesn't.)
What I want to do is for it to push onto the Navigation Controller stack, but am not sure how to setup the storyboard for that.
Any ideas?
You're expecting the UINavigationController hierarchy to extend itself into a presented popover. It won't. The same goes for presenting modal view controllers. If you were to log self.navigationController in popoverView, you would see that it is nil.
Embed popoverView into it's own UINavigationController. Remember that if you're overriding prepareForSegue:sender: and attempting to configure the popover, you will need to get the topViewController from destinationViewController as the destination is now an instance of UINavigationController.
Sounds like it should work, but if it doesn't try the following:
1. Click the segue that doesn't work and give it an identifier. Let's say it's PopoverToNewSegue.
In your implementation file for the popover view controller, add an action when the button is clicked.
That function should return void and add the following line:
[self performSegueWithIdentifier:#"PopoverToNewSegue" sender:self];
That should get your segue running. I've noticed that segues don't always work like you expect them to, but this one works for me without fail.