I am using the following code to push my view controller, except when the UIButton is pressed - nothing happens apart from the NSLog statement:
-(IBAction)doChangePasscode{
NSLog(#"Change Passcode Screen Loaded!");
ChangePasscode *cpscreen = [[ChangePasscode alloc] initWithNibName:#"ChangePasscode" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:cpscreen animated:YES];
}
I have imported the relavant files (using #import) so everything should be fine...
Why is this happening?
Thanks!
Have you debugged and checked that your navigationController isn't nil ?
You must check first from which button click action you are push viewcontroller That viewcontroller must be embed in UINavigationcontroller, after that you will able to push viewcontroller from that Navigation viewcontroller.
Your parent Viewcontroller must be embed in UINavigationviewcontroller.
Related
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 have a navigation view controller which navigates between some tableviews and I've just added an "edit" button inside the cells of one of the tables. What I'd like to happen is for the user to tap the edit button inside the cell and for the navigation controller to shunt across a new view where all of that cell's content is laid out for easy editing.
The cell, however, has no access to the navigation controller and cannot push a new view controller on to its stack. How can I do what I want?
Note that I am not using segues and storyboards as it's an old app and I want to continue supporting devices running iOS 4.
You should set the target of the button to the UIViewController that is already on the stack?
If you don't want to add this new view to the Navigation (Stack), Simply use the PresentModalViewController
// In action method for edit button
- (void)editButtonClicked {
EditViewController *editViewController = [[EditViewController alloc] initWithNibName:#"EditViewController" bundle:nil];
[self.navigationController presentModalViewController:editViewController animated:YES];
[editViewController release];
}
I'm not sure if you want this, but you can try:
// In action method for edit button
- (void)editButtonClicked {
EditViewController *editViewController = [[EditViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:editViewController animated:YES];
[editViewController release];
}
From the rootViewController I navigate to a UIViewController
if (self.contr == nil) {
ExampleViewController *controller = [[ExampleViewController alloc]
initWithNibName:#"Example"
bundle:[NSBundle mainBundle]];
self.contr = controller;
[controller release];
}
[self.navigationController presentModalViewController:self.contr animated:YES];
In the UIViewController I have the method
-(IBAction) goBack:(id)sender {
[self.navigationController dismissModalViewControllerAnimated:YES];
}
I added the signature to the .h file.
In the .xib file, I have a UIToolbar with a UIBarButtonItem. I connected the button to the File's Owner - goBack:
Everything appears in the screen, but when I click on the button, goBack isn't called. I also tried to do this programatically instead, but I got the same result - everything appears, but no reaction to the click.
Any ideas why it isn't working?
Edit:
I just found out something invisible is over the toolbar. If I click on a specific point (over the toolbar), then goBack: is called. Since I navigated to this screen using presentModelViewController, the navigation bar isn't appearing... but probably it's there and that's what is hiding the tool bar.
Have bind your Toolbar with File Owner?
As your UIBarButton is subview of UIToolbar so you have to bind Toolbar with File Owner.
Presenting a modal view controller do not require you to pass through a UINavigationController. I suggest you to change this:
[self.navigationController presentModalViewController:self.contr animated:YES];
[self.navigationController dismissModalViewControllerAnimated:YES];
to this:
[self presentModalViewController:self.contr animated:YES];
[self dismissModalViewControllerAnimated:YES];
Let me know if this helps.
Try this in the goBack method :
[self.navigationController popToRootViewControllerAnimated:YES];
If you are not hitting the breakpoint that means you did not connect them properly in the xib.
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.
I got a problem. I try to create a project with Navigation-based Application.
When I press rightBarButtonItem push to next view.
And that view got a UISegmentedControl right on UINavigationBar.
I use a IBAction when press Button A:
-(IBAction)backButtonPressed:(id)sender{
[self.navigationController popViewControllerAnimated:YES];}
when first view show up, I press Button A it will go back to main view.
If I press number 2 on UISegmentedControl , it become to another View,
and still the same method(-(IBAction)backButtonPressed:(id)sender).
But when I press Button B , it wont go back to main view..
as follow is my method about UISegmentedControl:
-(void)showSegmentedView:(id)sender{
AView *aView = [[AView alloc] initWithNibName:#"AView" bundle:nil];
BView *bView = [[BView alloc] initWithNibName:#"BView" bundle:nil];
if(seg.selectedSegmentIndex ==0) {
[[seg_view subviews] makeObjectsPerformSelector:#selector(removeFromSuperview)];
[seg_view addSubview:aView.view];
}
else if(seg.selectedSegmentIndex ==1){
[[seg_view subviews] makeObjectsPerformSelector:#selector(removeFromSuperview)];
[seg_view addSubview:bView.view];
}
}
Does anything wrong??
Thank in advance.
Mini
I assume seg_view's viewController has been pushed onto the navigationController's stack, self.navigationController on seg_view-Controller then returns your navigationController. However, as when add subviews to it from other viewControllers AView/BView, those UIViewControllers have no connection to seg_view's Controller or the navigationController itself. That means self.navigationController inside the new AView/BView is nil! Depending on your implementation, either backButtonPressed doesn't get called or popViewController in AView or BView does nothing since they don't have a navigationController. I suggest your either don't use other viewControllers (put the 2 views in the same nib as seg_view and interchange them) or push them on the navigationController's stack.