hi
In my application i am using TabBar.At first when I call loginControl,I am hiding the tab bar using [login hidesBottomBarWhenPushed=YES]; now if login is a success then I show detailViewController but I do not see the TabBar even after setting hidesBottomBarWhenPushed to NO.
what's the problem... can any one help me??
If you don't need your login view controller anymore you can pop it before push the second. This will do the work but there is strange animation in the back button. It still a solution :)
[navController popViewControllerAnimated:NO];
Edit:
Try this....
loginSuccessController *login = [[loginSuccessController alloc] initWithNibName:#"loginSuccessController" bundle:nil];
[self.navigationController popViewControllerAnimated:NO];
[self.navigationController pushViewController:login animated:YES];
can you try [self setHidesBottomBarWhenPushed:NO]; in your loginsuccesscontroller's viewwillappear or viewdidload
Use this method for hide and show tabbar :)
-(void)makeTabBarHidden:(BOOL)hide
{
UITabBarController *tabBarController = self.tabBarController;
if ( hide == tabBarController.tabBar.hidden ) {
return;
}
UIView *contentView;
if ( [[tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] ) {
contentView = [tabBarController.view.subviews objectAtIndex:1];
} else {
contentView = [tabBarController.view.subviews objectAtIndex:0];
}
if (hide) {
contentView.frame = tabBarController.view.bounds;
}
else {
contentView.frame = CGRectMake(tabBarController.view.bounds.origin.x,
tabBarController.view.bounds.origin.y,
tabBarController.view.bounds.size.width,
tabBarController.view.bounds.size.height - tabBarController.tabBar.frame.size.height);
}
tabBarController.tabBar.hidden = hide;
}
Related
I have a pageview which contains 4 pages. The pageView is using a navigation bar from previous UIViewController. I want set my UIPageView button in navigation bar to go to a new UIView. there are few problems. When i use performSegueWithIdentifier("CrankSetViewController", sender: sender) it give me a black screen. How to change to new UIView programatically without getting black screen?
In Swift -
pageViewController.setViewControllers(startingViewControllers,
direction: UIPageViewControllerNavigationDirection.Forward,
animated: true,
completion: nil)
you can set this in #IBAction
You can programmatically set the currently displayed view controller with a transition animation using setViewControllers:direction:animated:completion: on your page view controller.
Here is an example that presents view controllers with random background colors. You can adjust this to use your specific view controllers.
- (void)viewDidLoad
{
[super viewDidLoad];
self.pvc = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pvc.view.frame = CGRectInset(self.view.bounds, 200, 200);
[self.view addSubview:self.pvc.view];
[self.pvc setViewControllers:#[[self randomVC]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}
-(UIViewController*)randomVC
{
UIViewController *vc = [[UIViewController alloc] init];
UIColor *color = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1];
vc.view.backgroundColor = color;
return vc;
}
- (IBAction)previousButtonPressed:(id)sender {
[self.pvc setViewControllers:#[[self randomVC]] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:nil];
}
- (IBAction)nextButtonPressed:(id)sender {
[self.pvc setViewControllers:#[[self randomVC]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}
Hope it will help you...
I have an Iphone application in which i have 3 tabitems with a tabbarcontroller.Inside the tabbarcontroller each viewcontroller is a navigation controller.when selecting the second tab i have a view controller.when selecting a button on that i am pushing another view controller to the self.navigation controller.and in that viewcontroller i am pushing and go like that.But the problem is when i am selecting the tabitem again that pushedviewcotrooller is shown there.but i need that rootview there again when i am selecting the tab,i tried like this in my code but not worked,`
-(void)tabBarController:(UITabBarController *)tabbBarController didSelectViewController:(UIViewController *)viewController
{
if(tabBarController.selectedIndex==0)
{
//[viewController.tabBarItem setImage:[UIImage imageNamed:#"pinboard_hvr.png"]];
}
else if (tabBarController.selectedIndex==1)
{
NSLog(#"%#",viewController);
//[viewController.tabBarItem setImage:[UIImage imageNamed:#"pinboard_hvr.png"]];
// NSArray *array = [viewController.navigationController viewControllers];
NSLog(#"%#",array);
// [self.navigationController popToViewController:[array objectAtIndex:0] animated:YES];
[viewController.navigationController popToRootViewControllerAnimated:YES];
//[appdelegate.navigationController popToRootViewControllerAnimated:YES];
}
else if (tabBarController.selectedIndex==2)
{
//[viewController.tabBarItem setImage:[UIImage imageNamed:#"pinboard_hvr.png"]];
}
}
`i have tried both with poping to root and also by taking the array of view controllers,but not worked.Can anybody help me to achieve this?
The argument you have received in delegate is itself a navigationController.
So, change statement like below,
else if (tabBarController.selectedIndex==1)
{
[((UINavigationController *)viewController) popToRootViewControllerAnimated:YES];
//[appdelegate.navigationController popToRootViewControllerAnimated:YES];
}
Me too had a similar problem which I solved by the following code.
-(void)tabBarController:(UITabBarController *)tabbBarController didSelectViewController:(UIViewController *)viewController
{
else if (tabBarController.selectedIndex==1)
{
NSArray *mycontrollers = self.tabBarController.viewControllers;
[[mycontrollers objectAtIndex:1] popToRootViewControllerAnimated:NO];
mycontrollers = nil;
}
}
Hope this helps you.
hours ago I post a question on organizing portrait and landscape mode in iPhone and now I think I know how to do it using willRotateToInterfaceOrientation:duration.
The first screen is 'Map View' with one button that leads to 'Setting View'. The Map View does not support rotate but for the Setting View I made separate view for portrait and landscape and they swap accordingly when rotated.
, ,
As you can see when Setting button pressed SettingView is added on the view stack as usual. So basically I use three view controllers; Setting, SettingLandscape and SettingPortrait.
I still found problem in rotating view in iPhone when I use navigationViewController. Segmented control is not working. it crashes without error message. It used to working fine without rotation.- when I'm not using multiple view for rotation-.
rotateViewController.m
This is root view controller.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
-(IBAction) buttonPressed{
Setting *settingViewController = [[Setting alloc] initWithNibName:#"Setting" bundle:[NSBundle mainBundle]];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController: settingViewController];
[self.navigationController presentModalViewController:navController1 animated:YES];
[settingViewController release];
[navController1 release];
}
Setting.m
This view controller does nothing but swap views when rotate and shows appropriate view between portrait and landscape.
In Setting.m, I swap view as follow;
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight) {
NSLog(#"to Right");
SettingLandscape *setting_landscape = [[SettingLandscape alloc] initWithNibName:#"SettingLandscape" bundle:[NSBundle mainBundle]];
self.view = setting_landscape.view;
[setting_landscape release];
}
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
NSLog(#"to Left");
SettingLandscape *setting_landscape = [[SettingLandscape alloc] initWithNibName:#"SettingLandscape" bundle:[NSBundle mainBundle]];
self.view = setting_landscape.view;
[setting_landscape release];
}
if (toInterfaceOrientation==UIInterfaceOrientationPortrait) {
NSLog(#"to Portrait");
SettingPortrait *settingportrait = [[SettingPortrait alloc] initWithNibName:#"SettingPortrait" bundle:[NSBundle mainBundle]];
self.view = settingportrait.view;
[settingportrait release];
}
if (toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
NSLog(#"to PortraitUpsideDown");
SettingPortrait *settingportrait = [[SettingPortrait alloc] initWithNibName:#"SettingPortrait" bundle:[NSBundle mainBundle]];
self.view = settingportrait.view;
[settingportrait release];
}
}
In viewWillAppear, Setting view controller also has ;
self.title = #"Shell ";
self.navigationController.navigationBarHidden = NO;
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStylePlain target:self action:#selector(Done)] autorelease];
and Done is
- (void) Done{
[self dismissModalViewControllerAnimated:YES];
}
SettingLandscape.m
This view stacked on when the view is rotated. This view controller has it's navigation bar.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.title = #"Setting Landscape";
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
in viewDidLoad;
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"landscape:viewDidLoad");
//self.title = #"SettingLandscape";//not working!!
//self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:#"Done1" style:UIBarButtonItemStylePlain target:self action:#selector(Done)] autorelease];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
stringflag4MapType = [[NSString alloc] initWithString:#"blah"];
stringflag4MapType = [defaults stringForKey:#"flag4MapType"];
if (![stringflag4MapType isEqualToString:#"Hybrid"] && ![stringflag4MapType isEqualToString:#"Standard"] && ![stringflag4MapType isEqualToString:#"Satellite"]) {
segmentedControl4MapType.selectedSegmentIndex = 0;
}else if ([self.stringflag4MapType isEqualToString:#"Standard"]) {
segmentedControl4MapType.selectedSegmentIndex = 0;
}else if ([self.stringflag4MapType isEqualToString:#"Satellite"]) {
segmentedControl4MapType.selectedSegmentIndex = 1;
}else if ([self.stringflag4MapType isEqualToString:#"Hybrid"]) {
segmentedControl4MapType.selectedSegmentIndex = 2;
}
and following call does not get invoked. strange. doesn't matter rotation works anyway.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation==UIInterfaceOrientationPortrait) {
NSLog(#"to Portrait");// does not print out.
SettingPortrait *settingportrait = [[SettingPortrait alloc] initWithNibName:#"SettingPortrait" bundle:[NSBundle mainBundle]];
self.view = settingportrait.view;
[settingportrait release];
}
if (toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
NSLog(#"to PortraitUpsideDown");
SettingPortrait *settingportrait = [[SettingPortrait alloc] initWithNibName:#"SettingPortrait" bundle:[NSBundle mainBundle]];
self.view = settingportrait.view;
[settingportrait release];
}
}
ok now, as you can see from those snap shots there are two navigation bar and each has its bar button, Done and Item. The Done button came from Setting and the Item button from SettingPortrait or SettingLandscape. All button's selector is same, that leads back to map view. The button Done works fine, but the button Item crashes. I need a button on navigation bar after rotation that acts like back button . I guess once I did 'self.view = settingportrait.view;' the problem starts.
The reason why I need the Item button work is that the segmented control started crashing once I add code to support rotation. If I found reason how to make the Item button-that is inside rotation view- work I think I can make the segmented control work as well.
You can download the whole code at https://github.com/downloads/bicbac/rotation-test/rotate-1.zip
https://github.com/downloads/bicbac/rotation-test/rotate-1.zip
this sample code is amazing for me. It solve my problem of rotating view just by simple delegate method
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
my best attempt to answer question without looking at code (don't have time tonight :( )
When you present setting viewcontroller modally, your top viewcontroller is setting.
When rotation happens, you load setting_landscape or setting_portrait viewcontroller, but only retain the view inside setting_landscape|portrait. Thus, setting_landscape/portrait viewcontrollers are released. When device is rotated, it's probably "setting" viewcontroller receiving rotation message, not the "setting_landscape/portrait" viewcontroller because they are not pushed on to the viewcontroller stack.
So, when you click on item or segment control, it will call delegate, which is probably set to setting_landscape|portrait which is released already.
What is the message in console you get with crash?
My recommendation would be to build setting viewcontroller with segmented control, then use "willAnimateRotationToInterfaceOrientation:duration:" function to reposition the segmented control to the right position and frame. Just by returning YES to all orientation, rotation should be supported, doesn't it?
What was the reason for using two separate viewcontroller for landscape/portrait? (I do this sometimes, but rarely)
Edit* you need to use "willAnimateRotationToInterfaceOrientation" callback to animate the changes, not "willRotate..."
Okay, working on a transition between a view with a tabbar and another view which is to be an information/about view. I have the code to transition from the view with tabbar and to transition back to previous view, but during the transition back I lose the tabbar at the bottom. Not sure exactly how to approach this with the tabbar in the MainWindow.xib
E.g.:
(IBAction)backButtonPressed:(id)sender
{
TablesViewController *tvc = [[TablesViewController alloc] initWithNibName:#"TablesView" bundle:nil];
tvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:tvc animated:YES];
[tvc release];
}
Thanks,
np
Try presenting the modal transition from the containing instance of UITabBarController and not the UIViewController the action was triggered from.
- (IBAction)backButtonPressed:(id)sender
{
TablesViewController *tvc = [[TablesViewController alloc] initWithNibName:#"TablesView" bundle:nil;
tvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.tabBarController presentModalViewController:tvc animated:YES];
[tvc release];
}
I had the exact same problem, did a ugly solution:
- (IBAction)backButtonPressed:(id)sender {
[self.navigationController dismissModalViewControllerAnimated:YES];
}
I have an "add Contact" button which when on iPhone I present a navigation controller with root view controller of an ABNewPersonController modally.
If on iPad I have got a popover which I can display with the new person controller inside - nice.
The problem comes when trying to dismiss.
I can dismiss the popover when touching done or cancel within my implementation of didCompleteWithNewPerson using;
if(self.popoverController != nil)
[popoverController dismissPopoverAnimated:YES];
However, this doesn't dismiss when touching outside the popover.
I've returned YES for my popoverControllerShouldDismissPopover method and set the delegate of my popover to this. I've put an NSLOG inside this method and it's not dropping in there - Am I missing something?
Does anyone know how to dismiss the popover when touching outside?
Update - More Code
-(IBAction)contactsClicked:(id) sender{
ABNewPersonViewController *newPersonView = [[ABNewPersonViewController alloc] init];
[newPersonView setNewPersonViewDelegate:self];
[newPersonView setDisplayedPerson:newPerson];
UINavigationController *addContactNavController = [[UINavigationController alloc] initWithRootViewController:newPersonView];
[newPersonView release];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if(self.popoverController == nil){
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:addContactNavController];
self.popoverController = popover;
self.popoverController.delegate = self;
[popover release];
}
CGRect frame = [sender frame];
[popoverController presentPopoverFromRect:frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
} else {
[self presentModalViewController:addContactNavController animated:YES];
[addContactNavController release];
}
}
-(void)unknownPersonViewController:(ABUnknownPersonViewController *)unknownPersonView didResolveToPerson:(ABRecordRef)person{
[self dismissModalViewControllerAnimated:YES];
}
-(void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person {
NSLog(#"DONE OR CANCEL clicked!!!!"); //prints
if (self.popoverController != nil) {
[popoverController dismissPopoverAnimated:YES];
}
[self dismissModalViewControllerAnimated:YES];
}
The Done and Cancel buttons of the new person controller work, dismissing the controller and the popover (when running on iPad). I guess this means the delegate for the ABNewPersonViewController is implemented correctly. (?)
I'm guessing that I may be confusing the issue by having multiple controllers and my popover delegate method is getting hidden or something?
Thanks in advance
EDIT - Delegate method
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)thePopoverController{
NSLog(#"clicked outside the popover");//never prints
return YES;
}
From the docs:
Taps inside the popover window do not automatically cause the popover to be dismissed. Your view and view controller code must handle actions and events inside the popover explicitly and call the dismissPopoverAnimated: method as needed.
You should use the popover delegate methods –popoverControllerShouldDismissPopover: to listen for when it's about to be dismissed and do your saving etc. there.
Also, you should use self not this.