I have a login view controller at the start of the app. Then once the user login is successful I am taking the user to a view which has a table view inside it. I have embedded the table view inside a navigation controller. I have a segue which pushes user to the detail view. However as soon as I click on the row cell, I get the following error.
'Could not find a navigation controller for segue 'Event Details'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.''
But as I said above, there is a navigationview controller which embeds the table view. Whats causing this error?
the flow of the app is as follows
'->Login View NavigatinViewController->(View with a table View inside)->Details'
That looks like you may be missing a view controller.
Specifically, you should have something that resembles:
Login View > Navigation Controller > Table View Controller > Detail View Controller
Assuming you are creating a storyboard, the navigation controller can be easily added by selecting the table view controller and choosing Editor > Embed in > Navigation Controller.
Alternatively, if you want the navigation controller solely for a table view that is embedded within a view controller object, I recommend creating a container view in the view controller to display the table view and associated navigation controller.
To accomplish the latter, drag a container object into the view controller and size it to fit the table view that you want to display. Delete the view controller that the container view automatically creates.
Next, create a table view controller and segue to it from the container view. This segue will be an 'embed' segue. Lastly, you can then embed the table view controller you just created in a navigation controller and add the push segue from the table view controller to the detail view controller.
I think here you not use UINavigationController as a RootViewController.. and you use UIViewController as a rootViewController.. so may be this problem with this error
Just try to Follow this steps for the output..
Drag a new navigation controller into your storyboard - it will by default be attached to a tableview controller
Delete the tableview controller Right click on the navgiation controller, and connect the "Root View Controller" property to your existing view controller
Move the entry point arrow from your view controller to the root view controller
UPDATE:
see this example which through you can put validation and clearly push in your detailview...
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"AddPlayer"])
{
UINavigationController *navigationController =
segue.destinationViewController;
PlayerDetailsViewController
*playerDetailsViewController =
[[navigationController viewControllers]
objectAtIndex:0];
playerDetailsViewController.delegate = self;
}
}
Related
I am presenting a modal view controller with a tableView, and then want to perform a push segue when a cell is tapped inside the modally presented view controller.
I set up a view controller and a show (push) segue from the modal view controller to the new view controller, but when I call performSegueWithIdentifier, the new view is presented in a modal fashion (slides up) on top of the initial modal view, instead of coming in from the right.
Anyone know what's going on?
Thanks!
For anyone who has this issue in the future, I figured it out:
You need another navigation controller. So I perform a modal segue to a new navigation controller, and set the modal view controller as the root view controller of the navigation controller. I can then perform a show segue from the modal view controller to any other as normal.
:)
As of Xcode 11.4 (possible earlier) you can also just select the destination view controller and in the right inspector pane under the attribute inspector you have the option: "Transition style" and "Presentation" which will allow you to change from Automatic to Full Screen for example. That way you can overwrite that when you use "push" from a modally presented view controller, the segue will always present the next view controller modally.
I have a storyboard with a View Controller has my initial view. I am trying to segue to a NavigationController from a button click.
I can make the segue work when the button is clicked, but how do I get a reference to my NavigationController so I can populate my TableView?
Also, how do I make the table view go back to the initial view?
My Storyboard looks like this:
Thanks for the help.
First, in general we don't segue to nav controller, we segue with them, to another view controller. In theory, your segue will only work (unless you have done a lot of unnecessary coding) if you have properly setup the storyboard to make the Navigation controller the "initial" view controller, and your first View Controller as it's "root view controller" (most easily accomplished by the menu's "Embed in... > Navigation Controller" command).
Then in your code, you always have a simple access point for your nav controller: Any view controller which is currently in the stack of controllers managed by a nav controller can simply use it's navigationController property to access it. You can then use it's interface to popViewControllerAnimated: or similar.
In your View Controller, implement
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
and get your NavigationController via segue.destinationViewController.
But if you want to go back, you probably want the ViewController with the button to be connected to the NavigationController, not the other way around.
NC => VC with button -> TableVC
where => is a relationship segue and -> is a push segue.
So I have a Navigation Controller in which for every row select, I push ViewController A. However, ViewController A is another table of items.
So I'm having trouble figuring out how to make ViewController A also act as a navigation controller, in which for ever row I select in ViewController A, I can push a view controller, which, we'll name ViewController B.
I tried to add a Navigation Controller object inside an existing Navigation Controller to no avail.
How will I go about this?
Thanks in advance!
NavigationController has a rootController - in your case this is a some kind of table view controller. When you push view controller A - you use parent Navigation Controller. So you can push as many as you need view controllers via this "parent" navigation controller. Read carefully this section of apple docs
I have a Navigation Controller with a root table view which has several links. Tapping each link moves to the next view (by pushing it to the navigation controller's stack). But suppose that in that "next view", I have a UIButton that should take me further to another view (by pushing on to the same navigation controller's stack)...
View Controller-->first view-->second view-->third view..........
Now, I can easily access the Navigation Controller when I deal with the first view (and successfully push it to the Navigation Controller's stack) because it has been instantiated in the same file itself. What my real doubt is--How do you access a Navigation Controller in a far off view controller (eg, the third view or fourth view etc)? Please note that I am not using any separate delegate. All the Navigation Bar methods have been implemented in one file and connected to the Navigation Controller via an outlet.
When you push a ViewController onto a NavigationController the ViewController will automatically have it's navigationController property set. This means you can access the same NAvigationController no matter where you are in the stack.
-Update-
navigationController
In every UIViewController you can access that property.
So to in any other UIViewController that has been pushed onto the stack you should be able to just do this:
[self.navigationController pushViewController:othercontroller animated:YES];
Look at the documentation for UIViewController to see what other magic properties you have available.
Let's have an example.
In application I have a tab bar controller.
Tab bar has two items dynamically - two view controllers.
User can select any of tab.
Suppose user selects first tab.
First view controller is already loaded.
Now he clicks on a button of First view controller.
From First View controller -> Second View controller is pushed.
Now when user taps on tab bar first item
second view is popped out.
This is done through by default by tab bar controller.
Now, If I want to check following condition
if(tab bar first item-view controller has first view controller view)
then perform this
if(tab bar first item-view controller has second view controller view)
then perform this
How to implement this logic?
If you are using a UITabBarController, you can use its selectedViewController property to know what kind of view controller is on the screen, so if you have two subclasses of view controller FirstViewController and SecondViewController you can say
if([[tabBarController.selectedVIewController isKindOfClass:[FirstViewController class]])
//... do something
else ...