简体   繁体   中英

Navigationbar not displaying in UItableviewcontroller in storyboard

i created a UICollectionviewcontroller view and embed a UINavigationcontroller then I created one button in navigation bar.Again i created one UITableviewcontroller also i embed one uinavigationcontroller to it,when i click the button in UICollectionview navigation bar it shows the UITableviewcontroller up to this point is fine,but after this the navigation bar in UITableview controller is not showing at all.please help me

uitableviewcontroller图像

在此处输入图片说明

Try this piece of code to set the navbar to not be hidden:

-(void) viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:NO animated:YES];
}

Good luck

According to apple docs, this won't be showing the navigation controller. In order to show the navigation controller you need to instantiate a navigation controller first, and then load the table view controller as shown below :

LTBaseTableViewController *viewController = [[LTBaseTableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.window setRootViewController:navigationController];

I also struggled with this. Eventually solved by adding a Navigation Controller as defined in https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithConstraintsinInterfaceBuidler.html

除了@barryjones解决方案之外,您还可以使用导航控制器直接推送表视图控制器。

[self.navigationController pushViewController:yourTableViewController animated:YES];

Further to the above answers, I have also struggled in a similar way with moving programatically between tabs of a UITabBArController.

Most posts I read suggested

tabBarController?.selectedIndex = 0

however this would create the situation where the tab bar was no longer visible. Eventually solved by adding the following to the class in AppDelegate.swift

var tabBarController: UITabBarController?

and then also in AppDelegate, I modified didFinishLaunchingWithOptions as follows:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    tabBarController = window?.rootViewController as! UITabBarController
    return true
}

You can then use the following line anywhere inside your various view controllers

tabBarController?.selectedIndex = 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM