Ok, i need help for this action in Table
You can either use -popToRootViewControllerAnimated: or -popToViewControllerAnimated:
In your case for returning to view 1, use:
[self.navigationController popToRootViewControllerAnimated:YES];
If you want to return to a specific view controller, get it's reference and then do:
[self.navigationController popToViewController: specificViewController animated:YES];
If you are using Storyboard...
Create a Segue pointing to View1 VC and perform that Segue when the Back button is triggered.
If not, Sid's answer is correct.
Related
anybody know how to popToViewController ?
example:
introvideo-> welcomeview & tutorialview-> mainviewcontroller-> scannerviewcontoller-> questionview ->(if answer correct -> correctView) else ->wrongView
how do i pop back to mainView controller ?
One way is to iterate through the viewControllers array of the navigation controller. You can identify the correct one by tag, class name, etc.
based on what you have written It looks like MainViewController is the 4th ViewController on the navigation stack.
[self.navigationController popToViewController:[arrayOfViewControllers objectAtIndex:3] animated:YES];
should do the trick.
I don't know why dismissViewControllerAnimated:completion:. I just want to do it.
I start with a
[self performSegueWithIdentifier:#"my_segue" sender:self];
But is I call the dismiss than nothing happens. I can create another segue, but it create a new view controller.
My question is: How dismiss the performSegueWithIdentifier:sender:?
Do you have a navigationBar in the viewController that's calling:
[self performSegueWithIdentifier:#"my_segue" sender:self];
If so, you'll need to use:
[self.navigationController popViewControllerAnimated:YES];
to pop the view off the stack. There's one segue call, but the framework seems to call:
presentViewController:animated:completion:
or:
pushViewController:animated:
as appropriate.
Ray
You could just call
[self dismissViewControllerAnimated:YES completion:nil];
from the view controller since the view controller was pushed by segue.
[my_segue_view_controller dismissModalViewControllerAnimated: YES] ?
(not sure, but it works in my practice)
performSegueWithIdentifier:sender: itself isn't dismissed, that's just the method that's called to initiate a named segue. What happens in the segue is of more interest.
You're right that you should call dismissViewControllerAnimated:completion:, and it should be called by the presenting view controller, which has previously called the presented view controller using presentViewController:animated:completion:. For more info, see the UIViewcontroller docs.
Use the below code for Swift 4 version
self.navigationController?.popViewController(animated: true)
I am new to IOS, sorry in advance if I ask a stupid question.
I use UITabBarController and navigationController to control view.
At my last view, I would like to have a button when the button is pressed, view will return to rootViewController which I set by MainWindow.xib file and kill any process which run in app background.
this is my code in the last view before I want to back to rootViewController:
-(IBAction)doneButtonPressed:(id)sender{
JourneyIndexViewController *journeyIndexVC = [[JourneyIndexViewController alloc] initWithNibName:#"JourneyIndexViewController" bundle:nil];
[journeyIndexVC setDistanceLabelValue:self.distanceLabelValue];
[self.navigationController pushViewController:journeyIndexVC animated:YES];
[journeyIndexVC release];
[self dismissModalViewControllerAnimated:YES];
}
JourneyIndexViewController is the rootViewController that I set in MainWindow.xib.
Thank you very much for your advance support.
try
[self.navigationController popToRootViewControllerAnimated:YES];
You should take a look at this: UINavigationController Class Reference for better understanding
I am making a few assumptions here, but if JourneyIndexRootViewController is your rootViewController and is created in IB (in a nib), you do not need to re-crete it when pushing the button. It sounds like you simply need to remove the UINavigationController that you added on top of the rootViewController.
Try this. This should pop you back to the Previous View Controller.
[self.navigationController popViewControllerAnimated:NO];
Hope this helps
-(IBAction) btnReturn:(id) sender{
firstView * firstview =[[firstView alloc]initWithNibName:#"firstView" bundle:nil];
[self.view pushViewController:firstview animated:NO];
}
with the previsly code I see the first view but the navigation control increment. I wold came bak as was the navigation starting point. Any help?
pushViewController:animated: will add to the navigation stack; you want popViewControllerAnimated: to go back one view in the stack.
If you want to return to the very first (root) view controller, you want popToRootViewControllerAnimated:.
See: https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html
In your above code you are pushing a controller on self.view (firstView, I am considering it as controller as you are creating it using initWithNibName: method, but you should you proper naming conventions to avoid confusions.) But view do not have any such method pushViewController:. Instead you sould use if you really have self (the controller in which you are using this IBAction) in navigation stack.
[self.navigationController pushViewController:firstview animated:NO];
To pop controller from navigation stack, follow what #gregheo suggested.
Try using popViewControllerAnimated instead:
- (IBAction)btnReturn:(id)sender
{
[self.navigationController popViewControllerAnimated:NO]; // Or Yes if you would like to have an animation.
}
i have application in which i have display question on allcard view and all answer are displayed on backside of view.i done this by addsubview:ansview in allcardmethod.
now i have onr button that will on ansview function of that button is that to go to allcard to dispaly new question but i can not achived this....
please help
if you can use navigation Controller than use
[self.navigationcontroller pushViewController:viewController animated:YES];
where viewController is object of your controller class
and also you can use
[self.navigationController popToViewController:YES];
if u can add view using addSubView method than
use removeFromSuperView method
If i understand it correctly,you want to remove your second view from super view.try this code
[ansview removeFromSuperview];
also try this
[self.navigationController popViewControllerAnimated:YES];