Any ideas on how to add a Navigation Controller in iOS7 between a Table View and View Controller?
As soon as I embed the Navigation Controller to the table view the app crashes.
Without the Navigation Controller it works fine. But then the Table View becomes a View Controller. This is the code I'm using:
[self.navigationController performSegueWithIdentifier:#"setup" sender:self];
Here is my storyboard: http://sv.tinypic.com/r/1ztdnb/8
Okay, giving the comments here is what I think you want:
A LoginViewController which is a subclass of a UITableViewController. Should not display navigationBar.
A ProfileViewController also a subclass of a UITableViewController. Should display a navigationBar.
When a user taps LogIn button, ProfileViewController should be "pushed".
So the whole trick is to make navigation bar hidden for one view controller and visible for another. Well this is very easy to achieve - just use setNavigationBarHidden:animated: in viewWillAppear: for each view controller
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES/NO animated:animated];
}
Related
I have a view controller that has a navigation bar. It is the root view controller of the navigation controller. I have another view controller that can be segued from a button on the first controller. Up to this point, everything works fine; there are navigation bars on both view controllers.
However, from the second view controller, I want to be able to segue back to the first controller. When doing this, it removes the navigation bar from both of the view controllers.
How can I get the navigation bar on both view controllers with buttons as transitions? Thanks!
Implement below method in your both viewcontroller,
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
You may hiding navigationbar somewhere.
Try this in storyboard:
Select the navigation controller -> Attributes Inspector -> Under Navigation controller and Bar Visibility leave the "Show navigation bar" blank
There are two views in a tabbarviewcontroller. And the first tab has its view controller called myViewController which contain its IBOutlet. Pressing the button on the first view will present a view controller. After dismissing the view and back to the tab, the viewWillAppear of myViewController won't be called,but viewWillAppear of tabbarviewcontroller will. I need to reload the information on the first tab. If I use viewWillAppear in tabbarviewcontraller, how do I change the values of these property in myViewController? If anyone has idea ? Thanks.
If you want to call viewWillAppear of the viewController, you can add this to viewWillAppear of the TabBar
for (UIViewController *viewController in tabBarController.viewControllers)
{
[viewController viewWillAppear:YES]
}
While trying out storyboards for one of my projects I came across something for which I don't have a good solution;
I have a navigation-based application which shows a UITableViewController. The tableView is populated with user-created elements. Tapping an element cell brings up the detail view controller. The user can create a new element by tapping a button in the tableView. This brings up a modal view, which will handle the creation.
Now, when a user is done with creating the element and dismisses the modal view controller, I want the user to see the corresponding new detail view controller and not the tableview. But I can't figure out how to achieve this in storyboards.
Does anyone have a good pattern for this?
Current situation
TableView --(tap create)--> creation modal view --(finish creating)--> TableView
Should be
TableView --(tap create)--> creation modal view --(finish creating)--> detail view
You can put the creating view controller in a navigation controller and link the creation view controller to the detail view controller as well with a push segue. When you finish creating the data it will direct to an instance of detail view controller.
If you want to navigate back from details view directly to the table view, you can add a property to the details view controller, say #property (nonatomic) BOOL cameFromCreationViewController;. You can set this property in prepareForSegue: in the source view controller. In the details view make your own back button, and when it's tapped, you can do this:
if(self.cameFromCreationViewController){
[self.presentingViewController dismissViewController];
}
else {
[self.navigationController popViewController]
}
The best pattern I could come up with, is the same as the old pattern in code.
Add a property (nonatomic, weak) UINavigationController *sourceNavigationController to the modal view controller. When it becomes time to dismiss the modal view controller, add the following code:
DetailViewController *detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
detailViewController.element = newlyCreatedElement;
[[self sourceNavigationController] pushViewController:detailViewController animated:NO];
And to make sure the sourceNavigationController get set properly, add the following code in the prepareForSegue: of the TableView:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"newElementSegue"]) {
[[segue destinationViewController] setSourceNavigationController:self.navigationController];
}
}
I have a main view controller that lists a bunch of items, and when they tap on one of the items it segues them to the next view. However, in the next view, I don't want the navigation bar to be there, I only want it in the first view (I'm using a UIToolBar for the navigation bar, kind of like in iBooks).
How exactly do I go about achieving this? If I remove the main view controller from the navigation controller completely (unembedding, effectively) I can implement the nav bars selectively, but this solution doesn't allow segues, so it's no good.
My other solution was to call self.navigationController.navigationBarHidden = YES; in viewDidAppear for the second view, but with this, the UIToolBar that I added in my storyboard is pushed under the navigation bar that hasn't been hidden yet, and then when it does get hidden, it disappears and the UIToolBar "falls down", which is a pretty gross effect to the user.
What would be the best way to go about getting this effect?
The best way to do that is the following. In you viewWillAppear: in the first (rootViewController) of your UINavigationController, you set:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
and then in you viewWillDisappear, you the the opposite:
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
This way should work without nothing 'ugly' happening to the user.
I'm trying to use a popover as an intermediary menu between my main view and a modal view controller. I can successfully present the Modal view controller from the popover by using the following code:
UIStoryboard *storyboardiPad = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
cbwEditControlPanel *editCP = [storyboardiPad instantiateViewControllerWithIdentifier:#"EditCP"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:editCP];
[nav setToolbarHidden:NO];
[nav setModalPresentationStyle:UIModalPresentationFullScreen];
[nav setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:nav animated:YES completion:nil];
self.modalInPopover = NO;
The problem I'm running into is that when the EditCP modal view controller is dismissed, the main view controller never updates. I have a pagecontroller on the main view that should be updated to reflect the number of pages as set in the EditCP modal view controller, but for some reason the modal view controller being called from the popover prevents the main view controller from updating the pagecontroller. I've even tried calling the main view's "View Will Appear" method from the popover or modal view when they are dismissed, but even if the 'viewWillAppear' method is called the pageController will not update!
Any ideas what is preventing the pageController from updating? I even passed a reference to the pagecontroller to the modal view and tried to update it there, but it seems that from the time the popover is presented until it is dismissed, I cannot update the number of pages on the PageController.
Thank you!
So this is an old question but I also came across a similar problem recently when using a popover. My solution was to use an unwind segue to trigger my parent view to perform some action. In my case my parent view contains contact information and the popover contains a list of cites. All I wanted to do was to have the parent view update with the new city once the user selected it from the popover. So in my parent view I create my unwind function as follows:
In the .h:
- (IBAction)unwindToContactTVC:(UIStoryboardSegue *)unwindSegue;
In the .m:
- (IBAction)unwindToContactTVC:(UIStoryboardSegue *)unwindSegue
{
[self updateTableForOffice];
}
In the above .m file is where you would have the logic to do whatever it is you want to in the parent view. To connect this unwind segue go to the child view in the storyboard and control drag from the view icon to the exit icon. You should see a pop up with the name of your unwind segue.
Finally, give that unwind segue a name and then in the child controller in the viewWillDisappear() function call the segue as follows:
- (void)viewWillDisappear:(BOOL)animated
{
[self performSegueWithIdentifier:#"unwind-to-contact-tvc" sender:self];
}
I hope that helps. If someone has a better solution let me know.
Well, I half solved the problem. The only way to get an update function when the popover disappeared was to stop using Storyboards and programmatically present the popover, using the main view as the delegate. I then was able to update correctly inside the popoverControllerDidDismissPopover method.
However, I am still interested in finding a way to update the pageControl when the modal is dismissed, before the popover is dismissed.