How to identify previous view controller in navigation stack

You could use the UINavigationController‘s viewControllers property: @property(nonatomic, copy) NSArray *viewControllers Discussion: The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array. https://developer.apple.com/documentation/uikit/uinavigationcontroller You could use that to … Read more

presenting ViewController with NavigationViewController swift

Calling presentViewController presents the view controller modally, outside the existing navigation stack; it is not contained by your UINavigationController or any other. If you want your new view controller to have a navigation bar, you have two main options: Option 1. Push the new view controller onto your existing navigation stack, rather than presenting it … Read more

How to get root view controller?

if you are trying to access the rootViewController you set in your appDelegate. try this: Objective-C YourViewController *rootController = (YourViewController*)[[(YourAppDelegate*) [[UIApplication sharedApplication]delegate] window] rootViewController]; Swift let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate let viewController = appDelegate.window!.rootViewController as YourViewController Swift 3 let appDelegate = UIApplication.shared.delegate as! AppDelegate let viewController = appDelegate.window!.rootViewController as! YourViewController Swift 4 & 4.2 … Read more

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

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

Dismissing both UINavigation views and Modal views at once programmatically

If you want, in iOS 6.0 (and later) projects you can use an unwind segue. For example, you can: In your top level view controller (the one you want to unwind to, not the controller you’re going to unwind from), write an unwind segue method, in this case called unwindToTopLevel (personally, I find it useful … Read more

How to resize Title in a navigation bar dynamically

Used the below code in ViewDidload . Objective C self.title = @”Your TiTle Text”; UILabel* tlabel=[[UILabel alloc] initWithFrame:CGRectMake(0,0, 200, 40)]; tlabel.text=self.navigationItem.title; tlabel.textColor=[UIColor whiteColor]; tlabel.font = [UIFont fontWithName:@”Helvetica-Bold” size: 30.0]; tlabel.backgroundColor =[UIColor clearColor]; tlabel.adjustsFontSizeToFitWidth=YES; tlabel.textAlignment = NSTextAlignmentCenter; self.navigationItem.titleView=tlabel; Swift Version self.title = “Your Title Text” let tlabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: … Read more