I am new to iOS as my project depends on both navigation and the UITabBar controller.I have done the following steps
UITabBar contains 4 buttons and navigation bar contains 2 buttons i.e is common to all the screens
1)first i have taken the UITabBar controller and added four buttons to it
2)For each button to the UITabBar i have added the navigation controller
When i click the tabbar buttons all the views are showing fine and coming to UITabBar bar buttons I am facing the problem as below
suppose I am in UITabBar screen "A" and i clicked the navigation bar button i got the navigation screen ex as "Navscreen"that means now "A" contains "Navscreen" when i clicked tabbar button "B" and came back to UITabBar button "A" still its showing the "Navscreen"
To avoid such cases in the "Navscreen" view controller i have added the code as below in the view will appear
-(void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController
{
NSUInteger indexOfTab = [tabBarController.viewControllers
indexOfObject:viewController];
NSLog(@"Tab index = %u (%u)", indexOfTab);
if (indexOfTab==0)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
FirstViewController *firstview =
(FirstViewController *) [storyboard
instantiateViewControllerWithIdentifier:@"home"];
[self.navigationController pushViewController:firstview
animated:YES];
}
else if (indexOfTab==1)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
secondviewcontroller *secondview =
(secondviewcontroller *) [storyboard
instantiateViewControllerWithIdentifier:@"Medremainder"];
[self.navigationController pushViewController:secondview animated:NO];
}
if (indexOfTab==2)
{
UIStoryboard *storyboard = [UIStoryboard
storyboardWithName:@"Main" bundle:nil];
mymedView *mymed_view =
(mymedView *) [storyboard
instantiateViewControllerWithIdentifier:@"mymed"];
[self.navigationController pushViewController:mymed_view
animated:NO];
}
if (indexOfTab==3)
{
UIStoryboard *storyboard = [UIStoryboard
storyboardWithName:@"Main" bundle:nil];
Event_view *event_view =
(Event_view *) [storyboard
instantiateViewControllerWithIdentifier:@"Event_view"];
[self.navigationController pushViewController:event_view
animated:NO];
}
}
But in this case when click "Navscreen" its working and when I click the UITabBar "B" iam able to get the UITabBar screen.If i click again UITabBar "A" i can see "A" and when i click the UITabBar button "B" app is crashing.AS i am new to ios please help me with the possible solution if i make any thing wrong please suggest with the correct solutions.