I have 4 tab bar item. Each of them will have its own navigationController within it. I am trying to set a property of tab(1) rootViewController from tab(2). How do I get the instance of tab1(rootVC) class back?
i think use this line.....
[[tabBarController setSelectedIndex:0];
I think it will help you
[[self.tabBarController setSelectedIndex:0];
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 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
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.
I have a UITabBarController, and one tab is a UINavigationController. I have a search bar that goes to a certain view within the UINavigationController. The problem is that if the first view is not pushed by the UINavigationController, than it crashes because my search doesn't recognize the visibleViewController from this call:
UINavigationController *navController = [self.MainTab.viewControllers objectAtIndex:1];
FirstViewController *fVC = [navController visibleViewController];
What I don't understand is, before this code, I do this:
self.MainTab.selectedIndex = 1;
This code on its own selects the viewController in that tab, where then the view gets loaded to my knowledge. So shouldn't this be enough for the [navController visibleViewController] to get the current viewController? Thanks.
Try topViewController instead of visibleViewController.
FirstViewController *fVC = [navController topViewController];
From what you explain in your question and comments, I understand that your code tries to access an object of type FirstViewController, supposedly the first view to be pushed on to your UINavigationController, when it has not yet been created.
On the other hand, if you first programmatically select the tab, the view is created and everything works fine. Indeed, that view is created in a viewDidLoad method that is run when the tab is selected.
The solution I would suggest is avoiding accessing the UINavigationController visibleViewController directly from your search tab; instead, let your search code access the model (as in Model-View-Controller) for your app and store there the result; then, from the mentioned viewDidLoad method again access the model to read the search result and update/show the UI.
This is the clean solution, IMO. If you want a sort of workaround to your current design, then check the fVC value you get back from visibleViewController and if it is not what expected, then instantiate the view properly.
I hope this helps.
I know this has been answered, but I found another solution that might be helpful. In my case I was handling rotation differently for some viewControllers within my NavigationController, I did the following:
Subclass UINavigationController, then where needed in your new subclass you can access the current visibleViewController's title like so:
- (BOOL)shouldAutorotate
{
if ([[self visibleViewController].title isEqualToString:#"Special Case"]) {
return NO;
}
return YES;
}
This is not specific to rotation, this is just what I used it for. The only thing you have to do is set your self.title for each of the viewControllers you are checking against in their viewDidLoad, if they are set in IB or are not set they will be nil.
Assume that I have an application using tabbarcontroller with 10 UIViewControllers, once the UIViewController is more than 5, the Apple iPhone will generate the moreViewController for me to store rest of the UIViewController. My Question is, I want to implement a customized method to back to the more viewController, instead of using the default back in the left corner. How can I do so?
I tried with
[moreNavigationController popToRootViewControllerAnimated:NO];
but it seems that I have no luck. Thank you.
You can create an array of ViewControllers and then pop to the view Controller you need.
You can try this block of code
-(IBAction)home:(id)sender{
NSArray *array = self.navigationController.viewControllers;
[self.navigationController popToViewController:[array objectAtIndex:1] animated:YES];
}
Cheers
[self.navigationController popToRootViewControllerAnimated:YES]