I have a login screen after which home screen is shown. In home screen ,there are four buttons a,b,c,d. On pressing each button, say view a,b,c,d should appear related to view controller a,b,c,d. All these views are embedded in a UITabBar controller. The problem now is when I use the code
[self.tabBarController setSelectedIndex:2];
nothing happens and no view appears. How do i open the view using selected index method or any other method?
Thank You
Found the answer finally. Instead of
[self.tabBarController setSelectedIndex:2];
Use
UITabBarController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"IdentifierFromStoryboard"];
[self.navigationController pushViewController:controller animated:NO];
[controller setSelectedIndex:2];
This would work fine.
Related
I am navigating from TabBarController to another UIViewController.
aViewController.title = #"Product Name";
[self.tabBarController.navigationController pushViewController:aViewController animated:YES];
after navigating from the tabbar is not visible.
So change code
[self.navigationController pushViewController:aViewController animated:YES];
TabBar is visible but < Back button is not visible.
How to have tabbar and the default back button after navigating from tabbar?
I've just created a test project for this issue and you will see that it's working as expected.
https://github.com/Pei116/TabTest-iOS
I am experiencing an issue and I believe it's due to me incorrectly removing my view. I will try to explain and hope all can follow.
I have a UISplitview app which essentially has two views. The main detail view, and a view which is essentially a map. Upon selecting a certain string in the table this code is called (this code is in the detailview but the rainObject is passed in from a UIViewController.
-(void)setReceivedRainObject:(id)receivedRainObject{
if ([receivedRainObject isEqualToString:#"Test"]){
mapViewController *mapView=[[mapViewController alloc]initWithNibName:#"mapViewController" bundle:nil location:0];
[self.navigationItem setHidesBackButton:NO animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:YES];
[self.navigationController pushViewController:mapView animated:NO];
}
}
So the above code loads my map fine in the detailscreen as expected.
However, when I click the first option (test) from the left view controller, it calls a new view controller (viewcontroller2 with a row named test2) and that second controller calls a third( viewcontroller3 with a row named test3)
On the viewDidDisappear of viewcontoller3 and in the viewWillAppear of test I have this code
[self.detailViewController.navigationController popViewControllerAnimated:NO];
So when I drill down to viewcontroller, when I click the backbutton, it pops off one map, and when testview loads it pops the second. leaving my detail view showing exactly how I started.
However, I've noticed that if I clicked the "test" button twice, and try to go back, there is an "extra screen" that was supposed to be remove with pop. Would like to know how to remove this mass of views or to stop the program from adding so many.
Thanks
Just use
mapViewController *mapView=[[mapViewController alloc]initWithNibName:#"mapViewController" bundle:nil location:0];
[self.navigationController pushViewController:mapView animated:YES];
to navigate through the view controllers.
Here is my problem. I had a UITableViewcontroller to which UINavigation controller is Embedded. To UITableviewController I had Add screen and an edit screen. Add screen is working perfectly. When I click on the records on the table view cell it is able to redirect to the edit page (detailed view). When I hit on Submit button the page is not navigating to the tableview cell. Here is the below error.
Warning: Attempt to present on whose view is not in the window hierarchy!
Here is the code I was trying for navigation.
UINavigationController *questionnaireNavController = [self.storyboard instantiateViewControllerWithIdentifier:#"DLProjectsTasksubtasks"];
[questionnaireNavController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
DLProjectsTasksubtasks *qvc = (DLProjectsTasksubtasks *)[questionnaireNavController topViewController];
[qvc.tableView reloadData];
[self presentViewController:questionnaireNavController animated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
Between I was using a Segue for transfering the data from tableview data to Edit Screen
I think your segue is being pushed on the navigation controller rather than being presented modally. So you have two options, either change the segue in your storyboard to be modal and use the dismissViewControllerAnimated:YES completion: or keep it the way it is and use popViewControllerAnimated: on your navigation controller.
[self.navigationController popViewControllerAnimated:YES];
For passing the data to the previous page you can either pass a reference of the previous view controller OR accessing it through your navigationController.viewControllers. Index n-2 will be your previous view controller (n is the count of viewControllers).
I have structure of project as shown below.
On the left side I have MainViewController. There I have two buttons as English and Arabic. What I want to do is when I click English, I want to go English tab bar controller (HomeViewController).
Hence what I wrote is
- (IBAction)langEnglish:(id)sender {
HomeViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:#"enghome"];
[self.navigationController pushViewController:secondView animated:YES];
}
This is working perfectly, but I don't see tab bar.
Tab bar is missing from this.
Any idea what is going wrong?
Basically what I have is view controller as main controller and upon clicking button on this controller, tab view controller should get open...
Go to your main storyboard and select your main view controller. On top select Editor->Embed in->navigation bar.
EDIT: If this does not work push to your tab bar and use this code:
self.tabBarController.selectedIndex = 1;
What I did is as below
- (IBAction)langEnglish:(id)sender {
EngTabViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:#"engtab"];
[self.navigationController pushViewController:secondView animated:YES];
}
EngTabViewController is the UITabBarController and I assigned id to tab bar controller... this works like charm...
Means instead of viewcontorller, I used tabbarcontroller...
You shouldn't push a UITabBarController on a UINavigationController. Set it as the window's root view controller instead and the tab bar should be displayed as expected.
I have an application that looks like this;
Navigation Controller->Table View Controller->Navigation Controller2->Table View Controller2
The problem that I'm facing is that I want to have a "Back" button on Table View Controller2 that will take me back to the very first Navigation Controller. I can't figure out how to do this for the life of me, except by placing a button in the Table View Controller2's Navigation bar and creating a modal seque back to the first navigation controller. I don't think Apple will like that though. Can anyone help?
Try this:
NavigationController *nav = [[NavigationController alloc]init];
[self.navigationController pushViewController:nav animated:YES];
[nav release];