I would like to load a new ViewController/View upon validation of a login username/password. I have the following:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
...
...
ViewController *Workflow = [self.storyboard instantiateViewControllerWithIdentifier:#"Workflow"];
[self.navigationController pushViewController:Workflow animated:YES];
Then, in the story board, I added a new view controller and slapped a new uiview on there. I then changed the identifier of the ViewController to "Workflow". However, after clicking this button, nothing happens. Any ideas?
I would first NSLog the index of the button sending you the action, it's extremely useful for long alerts, and delegate methods with switch statements. If nothing is happening, then nothing is usually being done.
It sounds like you could be missing a UINavigationController from your storyboard. Unless your view controllers live within a UINavigationController, pushViewController: will have no effect.
If this is the case, what you need to do is:
Drag an instance of UINavigationController from the objects library onto your storyboard. Delete the root view controller that comes with it.
With the Navigation Controller selected on the storyboard, click the checkbox named "Is Initial View Controller" on the Attributes Inspector.
Hold down the Control key on your keyboard and drag with the mouse from the Navigation Controller to your first view controller (presumably the one where you are displaying the alert view) to create a segue. In the Storyboard Segues box that appears after you release, select "Relationship - Root View Controller"
Related
Right now I have:
TableViewController - displays a table that is populated with images and has UITableViewDelegate methods
ViewController- empty except for default viewDidLoad() fn
When I run my program, the screen is blank, presumably because my ViewController has nothing in it.
How do I make it so that it displays my TableViewController?
I have a hunch that I should use prepareForSegue, but am confused because when does prepareForSegue ever get called? I've read it is called before the viewDidLoad(). In that case, should I add a prepareForSegue function in my ViewController that directs to my TableViewController?
Click the ViewController in your storyboard, delete it, and then select your table view controller in the storyboard (click the little yellow icon on the left where the three icons appear right above the controller so that there is a blue outline around the controller). In the Attributes inspector in the utilities panel on the right in Xcode, check "Is Initial View Controller". Sounds like you don't need the other view controller at all.
If you want to segue to the table view controller from your view controller, add a button or some other UI control to the view controller, control-drag from that control to your table view controller, and then select a segue type. prepareForSegue() is called right before segueing; it's a way for you second view controller (in your case your table view controller) to get data that it may need from the first view controller.
You can set the root view controller in the app delegate didFinishLaunchingWithOptions method. Something like:
TableViewController *tableViewController = [[TableViewController alloc] initWithNibName:nil bundle:nil];
self.window.rootViewController = tableViewController;
[self.window makeKeyAndVisible];
should do the trick.
I would like to know why tha't happening: I have 2 view controllers embeded in navigation controller. All have superclass where I have something like that:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(#"Visible VC: %#",self.navigationController.visibleViewController.class);
}
So far everything works like a charm. Then I added third navigation controller which is the modal view controller. It also has super class like the others. Now I see strange thing. After click button to present modal View controller I see log: "Visible: (null)", but it's ok because third VC is not in navigation controller. When i click dismiss button to hide modal View controller I see 2 logs: "Visible: (null) Visible: ViewController3". My question is: Why visible view controller is not kind of class ViewController2 ? It should be, because third one was dismissed. How can i resolve it ? I need to have visible view controller kind of class View Controller 2.
I'm guessing that viewController2 is not the visible one yet when that is called.
Try accessing it in
viewDidAppear
instead of viewWillAppear.
Or, you can try to access the
self.navigationController.topViewController
property instead, that should return viewController2.
I have an initial 'parent menu' view controller with a 'photos' button (more buttons to come like 'events').
From the Photos button I have a simple ctrl-drag segue to a navigation controller which has a tableview as it's first view(albums), collections view(thumbs), then imageview(fullsize).
The problem I am having is:
I want to be able to segue back to the initial simple 'parent menu' view controller from the first table view after the nav controller.
I tried:
dragging a button into the table view's top menu bar area (it was considered a UINavigationItem) and dragging a segue back to the menu... didn't work.
setup outlet from button in the tableview menu area to its parent view and calling [self performSegueWithIdentifier: #"BackToMenu" sender: self]; from there, didn't work.
dragging a button into the table view as a last item and ctrl+dragging it as a segue to the menu: didn't work.
tried a segue going back from the nav controller to the menu and manually calling it, but the outlet function connected to the 'menu' button I dragged into the tableview top back NEVER gets hit.
What am I missing?
I plan to have a few navigation controllers going out from the menu page in the storyboard from multiple buttons.
You don't need a segue for this. You can create a button in your table view and link it to an action in your table view which dismisses the currently presented view controller (I'm assuming your segue that presented the navigation controller stack in the first place was of a "modal" type):
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
Alternatively, you can look into "Unwind Segues" but I haven't used these myself yet so wouldn't like to include details here.
You can drag a "Bar Button Item" to the left side of the first table view after the navigation controller. From there, do the control-drag back from the bar button item to the initial view controller, and choose a "modal" segue. While this answers your question, as #jrturton said in the comments below, this isn't optimized, because it will create a new instance.
If you want to do this programmatically (which will return to the existing instance), create an IBAction for the Bar Button Item on the table view controller. For example in iOS 6:
-(IBAction)returnToParentMenu:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
or in iOS 5:
-(IBAction)returnToParentMenu:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
What I wound up doing was making the nav controller first before anything and then my menu page was first with buttons down each respective path.
on the above: The ctrl+drag didnt work from the nav bar button, kept totally blowing up.
I did not realize I could go from nav controller to a regular view controller first. thought it needed to go to table view first since when you drag out a nav it comes paired with a table.
If I had 10+ 'points' in this strange forum I'd post a screen shot of the storyboard.
Thanks all
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.
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.