How to check if a view controller is presented modally or pushed on a navigation stack?

Take with a grain of salt, didn’t test. – (BOOL)isModal { if([self presentingViewController]) return YES; if([[[self navigationController] presentingViewController] presentedViewController] == [self navigationController]) return YES; if([[[self tabBarController] presentingViewController] isKindOfClass:[UITabBarController class]]) return YES; return NO; }

Programmatically get height of navigation bar

Do something like this ? NSLog(@”Navframe Height=%f”, self.navigationController.navigationBar.frame.size.height); The swift version is located here UPDATE iOS 13 As the statusBarFrame was deprecated in iOS13 you can use this: extension UIViewController { /** * Height of status bar + navigation bar (if navigation bar exist) */ var topbarHeight: CGFloat { return (view.window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0.0) + (self.navigationController?.navigationBar.frame.height … Read more

How to force view controller orientation in iOS 8?

For iOS 7 – 10: Objective-C: [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft) forKey:@”orientation”]; [UINavigationController attemptRotationToDeviceOrientation]; Swift 3: let value = UIInterfaceOrientation.landscapeLeft.rawValue UIDevice.current.setValue(value, forKey: “orientation”) UINavigationController.attemptRotationToDeviceOrientation() Just call it in – viewDidAppear: of the presented view controller.

iOS 15 Navigation Bar Transparent

To use your own colour scheme, use the following: Swift // White non-transucent navigatio bar, supports dark appearance if #available(iOS 15, *) { let appearance = UINavigationBarAppearance() appearance.configureWithOpaqueBackground() UINavigationBar.appearance().standardAppearance = appearance UINavigationBar.appearance().scrollEdgeAppearance = appearance } Objective-c if (@available(iOS 15.0, *)) { UINavigationBarAppearance *navBarAppearance = [[UINavigationBarAppearance alloc] init]; navBarAppearance.backgroundColor = [UIColor redColor]; [navBarAppearance configureWithOpaqueBackground]; [UINavigationBar appearance].standardAppearance … Read more

Navigation bar show/hide

This isn’t something that can fit into a few lines of code, but this is one approach that might work for you. To hide the navigation bar: [[self navigationController] setNavigationBarHidden:YES animated:YES]; To show it: [[self navigationController] setNavigationBarHidden:NO animated:YES]; Documentation for this method is available here. To listen for a “double click” or double-tap, subclass UIView … Read more

Setting action for back button in navigation controller

Try putting this into the view controller where you want to detect the press: -(void) viewWillDisappear:(BOOL)animated { if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) { // back button was pressed. We know this is true because self is no longer // in the navigation stack. } [super viewWillDisappear:animated]; }

How to add a right button to a UINavigationController?

Try doing it in viewDidLoad. Generally you should defer anything you can until that point anyway, when a UIViewController is inited it still might be quite a while before it displays, no point in doing work early and tying up memory. – (void)viewDidLoad { [super viewDidLoad]; UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@”Show” style:UIBarButtonItemStylePlain target:self action:@selector(refreshPropertyList:)]; … Read more

How to change the Push and Pop animations in a navigation based app

I did the following and it works fine.. and is simple and easy to understand.. CATransition* transition = [CATransition animation]; transition.duration = 0.5; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; transition.type = kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade //transition.subtype = kCATransitionFromTop; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom [self.navigationController.view.layer addAnimation:transition forKey:nil]; [[self navigationController] popViewControllerAnimated:NO]; And the same thing for push.. Swift … Read more

Execute action when back bar button of UINavigationController is pressed

Replacing the button to a custom one as suggested on another answer is possibly not a great idea as you will lose the default behavior and style. One other option you have is to implement the viewWillDisappear method on the View Controller and check for a property named isMovingFromParentViewController. If that property is true, it … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)