My Tab bar should stay on screen when I click on button in Test2 View Controller.
I've set Test 3 View Controller's Bottom bar to inferred and tried Translucent tab bar. I've changed the segue from push to modal. I've tried this solution, but doesn't work for iOS7.
TestTabBarController.m this doesn't work either:
- (void)viewDidLoad
{
Test3ViewController * viewController1 = [[Test3ViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *homeNavi=[[UINavigationController alloc]initWithRootViewController:viewController1];
self.viewControllers = [NSArray arrayWithObjects:homeNavi, nil];
}
This also doesn't work:
- (IBAction)buttonpress:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
Test3ViewController * test3ViewController = (Test3ViewController *)[storyboard instantiateViewControllerWithIdentifier:#"test3View"];
[self.navigationController pushViewController:test3ViewController animated:YES];
}
First:
Your link Test2 to Test3 in storyboard is Modal,
change it to Push:
And u'll see your navigation bar.
Second:
Don't use the segue mechanism for your task.
Use the pushViewController on UINavigationController
A modal view will cover the tab bar. If you want to load a view after you hit the 'Button' do the following:
- (IBAction) loadNewView:(id) sender {
Test3ViewController * viewController1 = [[Test3ViewController alloc] initWithNibName:nil bundle:nil];
[[self navigationController] pushViewController:viewController1 animated:YES];
}
Then link that up with your button...
The answer is: Add a Navigation controller between Test Tab Bar Controller and Test2 View Controller.
Related
I have a login view that takes a username and password and grabs an webpage string. I want to then pass this information to the next view where itll load the html string. The problem is that the second view is managed by a tab bar controller (the one that was generated by default tab bar template in xcode). However, when i segue into it I lose the tab bar controller. My segue goes from the login view controller directly to the second view. I tried directing it to the tab bar controller itself but I wasn't able to pass the data from the login view to the first view. Any tips or workarounds for this?
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:#"ShowSchedule"]){
SocialSchedulerFirstViewController *scheduleController = (SocialSchedulerFirstViewController *)segue.destinationViewController;
NSString *webPageCode = htmlString;
scheduleController.htmlString = webPageCode;
}
}
You have to change the segue to go from your login view controller directly to tab bar controller. You had problem with passing data because you try to pass it to tab bar,I guess, but you should get reference to your view controller first. Try this:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:#"ShowSchedule"]){
UITabBarController *tabar=(UITabBarController*)segue.destinationViewController;
SocialSchedulerFirstViewController *scheduleController = (SocialSchedulerFirstViewController *)[tabar.viewControllers objectAtIndex:0];;
NSString *webPageCode = htmlString;
scheduleController.htmlString = webPageCode;
}
}
It will works if your SocialSchedulerFirstViewController is first tab of tab bar controller.
Remove segue login to tabbar controller, you need to do it programatically
Set your tabBarcontroller in storyboard as initial controller
Inside AppDelegate.m
if (authenticatedUser)
{
self.window.rootViewController = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
}
else
{
UIViewController* rootController = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"LoginViewController"];
UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];
self.window.rootViewController = navigation;
}
Inside LoginController
- (IBAction)actionLogin:(id)sender {
AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];
appDelegateTemp.window.rootViewController = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
}
I'm using storyboards with this. On the storyboard I have a "mainpage" uiviewcontroller that has a button which when tap will call another uiviewcontroller (choosewinner) to pop up. But this choosewinner vc has a uinavigation controller attached to it, reason why is so that it can go back and forth easily. Now I can call the uiview as a modal pop up but it doesn't show it's uinavigation.
This is the method called when the button is tapped. Thoughts?
- (void)updateWinner{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
MatchWinnerViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"WinnerViewController"];
vc.modalPresentationStyle = UIModalPresentationFormSheet;
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:vc animated:NO completion:nil];
vc.view.superview.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
vc.view.superview.bounds = CGRectMake(0, 0, 800, 600);
}
Even though you have the MatchWinnerViewController with UINavigationController attached to it in the storyboard, if you want to present it modally with the UINavigationController, you need to supply the navigation controller as the parameter to the method instantiateViewControllerWithIdentifier.
The reason is that for modal presentation, it takes the root view controller, and a navigation controller is also a view controller.
current version of my project :
I have 5 different UIViewControllers in my app. I've set my
FirstViewController to be the Initial View Controller using the
Attributes Inspector. I move back and forth from one ViewController to
another by using buttons to which I assign modal segues, from one
ViewController to another, using the StoryBoard
What I want to change:
I want to keep the navigation buttons obviously, delete the modal segues and use
a UINavigationController instead. If I understand the concept
correctly, when using a UINavigationController I need to go into each
UIButton-IBAction and at the very end of the method I have to push the next
ViewController I want to move to, onto my NavigationController (do I also
have to pop the current one first?). However, I can't figure out how
to implement all that correctly.
What I've done so far:
I removed all modal segues from the storyboard and kept the navigation buttons along with their corresponding IBActions
I unchecked the box in the Attributes Inspector that was making my FirstViewController the initial View Controller of my app
I went into my AppDelegate.m and tried to create the Navigation Controller there and make my FirstViewController be the RootViewController
MyAppDelegate.m
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *myFirstViewController = [[FirstViewController alloc] init];
UINavigationController *myNavigationController = [[UINavigationController alloc] initWithRootViewController:myFirstViewController];
[myNavigationController pushViewController:myFirstViewController animated:YES];
// Override point for customization after application launch.
return YES;
}
I then tried to test if the above was working by going into the IBAction of a
navigation button on my FirstViewController and implemented the
following in order to move to my SecondViewController when the
button is pressed :
FirstViewController.m
- (IBAction)goRightButton:(UIButton *)sender
{
// some code drawing the ButtonIsPressed UIImageView on the current View Controller
UIViewController *mySecondViewController = [[SecondViewController alloc] init];
[self.navigationController pushViewController:mySecondViewController animated:YES];
}
but nothing happens. What am I doing wrong ?
You are not linking your XIB file. Please add your navigation controller as
UIViewController *myFirstViewController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:myFirstViewController];
Use following code to move from one view to another
UIViewController *mySecondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:mySecondViewController animated:YES];
If you are using a storyboard, you should just drag in the navigation controller there and hook it up to your app delegates. As long as it is the main storyboard, and you have identified a view controller to load first, you do not need to load any views in your app delegate.
In order to push a view programmatically that's in a storyboard, you need to do something like the following:
//bundle can be nil if in main bundle, which is default
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
MyCustomViewController *customVC = (MyCustomViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:#"customVC"];
//standard way
[self.navigationController pushViewController:customVC animated:YES];
//custom animation
[UIView transitionWithView:self.navigationController.view duration:0.5 options:UIViewAnimationOptionTransitionCurlUp animations:^{
[self.navigationController pushViewController:customVC animated:NO];
} completion:nil];
You identify the view controller with the identifier you add in the storyboard editor. Below are some screenshots to help show what I mean.
My main menu (a ViewController) is embedded in a NavigationController that I added in the storyboard in Xcode4.
I have a button in my menu, displaying a new view. To display it I use :
- (IBAction) display : (id) sender
{
if(!anotherView) anotherView = [[AnotherView alloc] initWithNibName:#"AnotherView" bundle:nil];
[self presentModalViewController:anotherView animated:NO];
}
My other view is correctly displayed with all its objects and elements. Excluding my NavigationController's bar, that doesn't appear. Why ?
Thanks for your advices
You are presenting the view modally what you probably meant was
[self.navigationController pushViewController:anotherView animated:YES]
of course what you really want to do is not mix and match storyboard and non storyboard flows unnecessarily like this and have the storyboard do this for you
you are presenting your viewController modally. If you want to use the navigation controller you have to push your view onto the navigation stack.
replace
[self presentModalViewController:anotherView animated:NO];
with
[self.navigationController pushViewController:anotherViewController animated:YES];
You can still present your view modally without losing the navigation bar. Try this code:
AnotherView *tempAnotherView = [[AnotherView alloc] initWithNibName:#"AnotherView" bundle:nil];
[self setAnotherView:tempAnotherView];
[tempAnotherView release];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:self.anotherView] autorelease];
[self.navigationController presentModalViewController:navController animated:YES];
Hope it helps! :)
I have a view controller that is inside a popover, and I want to present a modal view controller from it. Here's my code:
EditDateViewController *dateViewController = [[EditDateViewController alloc] initWithNibName:#"EditDateViewController" bundle:[NSBundle mainBundle]];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:dateViewController];
navController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:navController animated:YES];
[dateViewController release];
[navController release];
The result is this:
alt text http://cl.ly/5300e4f8f5d440d3f850/content
For some reason, the navigation bar background is transparent (or black?) even though I did not configure it that way. I tried manually setting the tintColor property of the navigation bar in the viewDidLoad method of the modal view controller, but it had no effect.
Try this
dateViewController.modalInPopover=YES;
self.navigationController.modalInPopover=YES;