I'm trying to push a UIViewController on to my navigation stack using the following:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle: nil];
TestViewController *lvc = (TestViewController *)[storyboard instantiateViewControllerWithIdentifier:#"TestViewController"];
[self.navigationController pushViewController:lvc animated:YES];
TestViewController has a scene in the storyboard and ViewDidLoad is always called BUT if I trigger this code with a button click I get a blank view added the the navigation stack. It has a navigation header and back button. If I click the back button, the calling view is also blank.
If I call this code in the ViewDidLoad of my calling UIViewController it works as expected and I can see the view from the storyboard. The back button then works fine.
Could my original view be getting deallocated?
Thanks very much
Related
I am opening second view controller on button click from fist viewController,but its animating from bottom.I want to open it in right to left.
You may be presenting the second view controller on first view button tap.
The view transition from right to left will work when you do pushing a second view.
For enable pushing the second view, at first your first view should be inside navigation controller.
If your first view is already inside a navigation controller then do the following for pushing second view:
Case 1: If your are using storyboard and First view is already embedded in Navigation controller
set storyboardID for the second view controller in storyboard (Eg. here storyboardID is same as the class name)
Do this code on your button tap of first view:
SecondViewController *secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
[self.navigationController pushViewController:secondViewController animates:YES];
Case 2: If you are using storyboard but First view controller is not embedded in Navigation Controller:
1. Embed the First view in Navigarion controller
1.1. Open storyboard file and select the First View Controller
1.2. Goto Editor->Embed In-> Navigation Controller.
Then do the step Case:1's 2nd step.
Case 3: If you are using XIB files and first view is not in navigation controller.
1. For loading first view in AppDelegate.m application:didFnishLoading: method do as follows:
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
self.window.rootViewController = navigationController;
Then for pushing second view on first view button do as follows:
SecondViewController *secondViewController = [[FirstViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondViewController animates:YES];
If this is not helpful, then just post what you did exactly then exact solution can be given. Because what approach you are using to load view is not mentioned in your question.
Use
[self pushViewController:yourViewController animated:YES];
instead of
[self presentViewController:yourViewController animated:YES completion:nil];
The first piece of code pushes the second view controller in the screen from right to left.
The second line of code, which is what you have probably written in your app presents the view controller modally, meaning from bottom to top.
I have started an iOS app with storyboard. In my app, mainStoryBoard starts with navigation controller. From navigation's view controller, I pass the controller to a second viewcontroller with a push segue by programatically ([self performSegueWithIdentifier:#"currencyClick" sender:self]). On the second view controller I have a button. On button click I want to go back to navigation's viewcontroller like [self.navigationController popViewControllerAnimated:YES] but here self.navigationController popViewControllerAnimated:YES is not working . In my project I unticked Shows navigation Bar in Navigationcontroller.
NavigationController-(root viewcontroller)-> viewController --(push segue with [self performSegueWithIdentifier:#"currencyClick" sender:self];)-->CurrencyViewcontroller
In currencyviewController I have a button. On button click I want to implement navigation back button click event. How do I implement a BACK Button programmatically, [self.navigationController popViewControllerAnimated:YES] is not working in this case.
Please help me to solve this problem..
Thanks in advance
to call secondcontroller in your first view controller use:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"mainStoryBoard" bundle: nil];
SecondViewController *rvc = (SecondViewController *)[storyboard instantiateViewControllerWithIdentifier:#"SecondViewControllerNameInYourStoryBoard"];
[self.navigationController pushViewController:rvc animated:YES ];
instead of self performSegue... Then in your second controller pop should work.
I'm loading a table view control by pressing a button in view controller
.The code in my Viewcontroller.m is
-(IBAction)go:(id)sender{
TableViewController *sec=[[TableViewController alloc]init];
sec.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:sec animated:YES];
}
Now my table view controller loads..Now i need to add a navigation bar which have title and back button which loads view controller.I also want to know how to assign action to that back button where i can load view controller
I tried out in google which all makes tableviewcontroller as root view controller where in my app rootviewcontroller is view controller..Is there a way to add that in my xib or by programmatically.
Help pls..
You can do this:
-(IBAction)go:(id)sender{
TableViewController *sec=[[TableViewController alloc]init];
UINavgationController *nav = [[UINavgationController alloc] initWithRootViewController:sec];
nav.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:nav animated:YES];
}
For the impatient:
I want to have a navigationcontroller who's root viewcontroller is a tabbarcontroller, similar to the iPad application. I am using IOS 5 and Storyboards.
For the reading inclined:
In my storyboard I have 6 tabs in a UITabBarController that is embeded in a UINavigationController, giving it a "More" button after 3 tabs are shown.
doing so gives me two navigation bars when more is pressed:
So I subclass TabBarController:
//#implentation MyTabController
- (void)viewDidLoad
{
self.moreNavigationController.wantsFullScreenLayout = NO;
self.delegate = self;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
// hide nav bar if current controller is "More" controller
self.navigationController.navigationBarHidden =
viewController == self.moreNavigationController;
}
Great, this gives me:
My guess was that i needed to relayout the views to account for the statusbar, so i try
[self.view setNeedsLayout:YES];
but i get an error saying UIView does not contain a selector for setNeedsLayout so...
How do I get the moreNavigationController.navigationBar to account for the statusbar?
Update:
I have a second related issue with this. When I hit the "Edit" button the edit controller shows modally. Its navigationbar displays underneath the insured controller (after an animation), and does not receive touches.
Pushing a tabBarController into a NavController isn't recommended, instead set a NavigatorController for every tabBar View controller, and set the TabBarController as the main window root view controller.
If you want to be able to show a screen before showing the tabbar, a solution is to push in all the navigator controllers the previous view controller, followed by the one you want to show (that way all navbars has the backbutton). Then set hidesBottomBarWhenPushed = YES to the first view controller, that way it won't show the tabBar.
Example Code:
UIViewController *prevc = [[UIViewController alloc] init];
//prevc.hidesBottomBarWhenPushed = YES;
//Do this for every VC that will be a tabBarItem
UIViewController *vc1 = [[UIViewController alloc] init];
UINavigationController *nv1 = [[UINavigationController alloc] initWithRootViewController:prevc];
[nv1 pushViewController:vc1 animated:NO];
//Remember to set the tabBarItem!
UITabBarController *tb = [[UITabBarController alloc] init];
tb.viewControllers = [NSArray arrayWithObjects:nv1, nv2, nv3, nil];
I just realized that setting hidesBottomBarWhenPushed to the previous ViewController won't work well, but If you show prevc first, and then push the following viewController, you won't have problems. But if anyway you wan't to hide the tab bar while doing a pop, please check this:
hidesBottomBarWhenPushed but when popped
I have also faced a similar problem. In my application also, there is a Tabarcontroller inside a Navigation controller. When i try to switch to a view controller in more navigation controller programatically (like : [self.tabBarController setSelectedIndex:X]; ) the same issues appears in my application. But the following code solves my problem.
self.tabBarController.moreNavigationController.navigationBarHidden = YES;
I have a View application with a Single UIViewController. I then add a UITableViewController through the IB, and I am trying to display the UITableViewController through a button press in the UIViewController (my main view). My button press (IBAction) contains the following code through which I am trying to push my UITableViewController view and display it:
DataViewController *dataController = [[DataViewController alloc] initWithNibName: #"DataViewController" bundle:nil];
[self.navigationController pushViewController:dataController animated:YES];
[dataController release];
My DataViewController is not at all getting pushed into the stack and displayed,
Also I have checked that in the code above, self.navigationController=nil
Probably this is the source of the problem. If so, how to rectify it?
Please help.
UINavigationController *navCtrlr = [[UINavigationController alloc]initWithRootViewController:yourfirstviewController];
[self.window setRootViewController:navCtrlr];
navCtrlr.delegate = self;
navCtrlr.navigationBarHidden = YES;
Create navigation controller in appdelegate.m then you can navigate to any uiviewcontroller
You need to actually create a UINavigationController. The navigationController property tells you whether your DataViewController is currently in a UINavigationController's hierarchy; if not (as in this case), the navigationController property returns nil.