Tabbarcontroller behaviour - iOS - ios

I'm trying to arrive at tab bar C on IBAction from a button the newViewController. But when I arrive the tab bar controller shows A's view instead of C's view. If using
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"MyInitialViewController"];
[vc presentModalViewController:navController animated:NO];
I end up creating view of C tab bar with no tabbar options and navigation bar like this
Any help would be greatly appreciated! thank you

If you use storyboards and want to keep the navigation bar and tab bar, you should use
[self.navigationController performSegueWithIdentifier:#"MyInitialViewController" sender:self];
instead of using modal presentation

Related

iOS:Navigation bar not showing when is embed from the main view controller

I have the following layout on my story board:
When I click on the button I load the blue view controller:
- (IBAction)blue:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
BlueViewController *blue = [storyboard instantiateViewControllerWithIdentifier:#"BlueViewController"];
[self presentViewController:blue animated:YES completion:nil];
}
The blue view controller has navigation bar embed. But doesn't show on either the blue viewcontoller or the pink view contoller:
My question to you guys is what I'm doing wrong? or why does the view controller is not showing ?
Give the navigation controller for blue VC a storyboard ID, and present that instead of blue VC.
If you present a VC, even though it has a navigation controler it doesnt show up as you present only the view cotroller.
- (IBAction)blue:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *blueNavVC = [storyboard instantiateViewControllerWithIdentifier:#"BlueViewControllerNavigationController"];
[self presentViewController: blueNavVC animated:YES completion:nil];
}
And when you want to move from blue to pink, you need to push to pink controller as pink is part of the blue navigation controller stack!
If you want to present on a view controller then you have to add a custom view in in top of your controller cz it's on the your navigation controller. If you push a controller then you don't need the above. You will find the same navigationbar to all. Cz It's within your navigation controller stack.

navigation controller can't back

UINavigationController pushes from controllerA to controllerB,
but the navigation bar still show controllerA's . (custom content is controllerB,the navigation bar is controllerB's is right result)
Here is few lines from my method
MKMCComboListTVC *controllerVC = [[MKMCComboListTVC alloc] init];
[self.navigationController showViewController:controllerVC sender:nil];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MYAddShopTVC *controllerVC = [mainStoryboard instantiateViewControllerWithIdentifier:#"MYAddShopTVC"];
controllerVC.nameList = transNameList;
[self.navigationController showViewController:controllerVC sender:nil];
then when I click back button, controller is not poped back. It shows ViewController from controllerB to controllerC, custom content is in the controllerC, the navigation bar is controllerA's. In short it can push next controller ,but can't back. so navigation bar doesn't match custom content.
How can I fix this?

Add semi-transparant background viewcontroller with search bar throughout app

need help in adding search bar ViewController which whose SearchBar will be in NaviagationBar with Back button (navigation search i achieved - self.navigationItem.titleView = searchBarView) throughout app, but until it has search i want to show previous ViewController in background with semi-transparent black color just like i achieved in Android :
i can add semi-transparent ViewController to current ViewController :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
vc.view.backgroundColor = [UIColor clearColor];
[vc setTransitioningDelegate:transitionController];
vc.modalPresentationStyle= UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:nil];
but what it is doing that it opens SecondViewController in transparent without NavigationBar, the FirstViewController has NavigationBar
And when the SecondViewController is opened it should have SearchBar in NavigationBar and it shouldn't be Transparent as i achieved in Android.
There will be n number of ViewController which will add this same controller as Overlay Controller with NavigationBar and back button.
Please Help.
I found some solutions which involve taking a snapshot of the view and adding them to your navBar controller.
From Apple:
https://developer.apple.com/library/ios/qa/qa1817/_index.html
Other interesting option:
iOS iPhone is it possible to clone UIView and have it draw itself to two UIViews?
In you code snippet you just create new SecondViewController and present it like modal. It appears without navigation bar because you create it without Navigation Controller.
If you want to keep SecondViewController in the same navigation stack as previous ViewController with navigation bar and default Back button you should call:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
[self presentViewController:vc animated:YES completion:nil];
[self.navigationController pushViewController:vc animated:YES];
To make SecondViewController like semitransparent, take screenshot of previous view controller, pass this image to SecondViewController and use it like background. You can apply this image to additional ImageView on your SecondViewController view or just call:
self.view.backgroundColor = [UIColor colorWithPatternImage:self.backgroundImage];

iOS: Showing the UIViewControllers when UITabBar and UINavigationBar buttons cliked

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.
In your didSelectViewController:, you seem to be pushing new controllers onto self.navigationController multiple times? Each time you select a tab this code will push another controller loaded from storyboard on top of what is already there. This is probably what is messing up your navigation items.
Should you not just be allocating separate navigation controllers once to each tab so this is all automatic?
In storyboard/code allocate separate navigation controllers for each tab. In each navigation controller, create it with a root controller based on what you are loading from storyboard for each tab. You only need to create this once somewhere in your main controller. Then allocate the navigation controllers to separate tabs in storyboard or in code set the array of controllers to be an array of your created navigation controllers.
It should then all be automatic without you needing to implement didSelectViewController: at all since each tab will simply cause the appropriate navigation controller to be presented and its associated navigation bar.

iOS: How to programmatically navigate/jump to different scenes managed by Navigation Controller?

I have a series of views that are managed under a Navigation Controller. Is there a way to programmatically (in iOS5+) jump (push/pop) to different views? For instance, I have
NavigationController->RootViewController->DetailViewController1->DetailViewController2->DetailViewController3
How can I, say, jump from RootViewController to DetailViewController3, and then jump back to DetailViewController1?
Thanks.
You can try something like this.
Get your VCs from storyboard. (You have to set identifiers in storyboard)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *DetailViewController1 = [storyboard instantiateViewControllerWithIdentifier:#"DetailViewController1Identifier"];
UIViewController *DetailViewController3 = [storyboard instantiateViewControllerWithIdentifier:#"DetailViewController3Identifier"];
Push VCs way you need.
[self.navigationController pushViewController:(DetailViewController1) animated:YES];
[self.navigationController pushViewController:(DetailViewController3) animated:YES];
Now, when you press "back" you'll see DetailViewController1.

Resources