xcode 导航栏未显示在故事板的 UItableviewcontroller 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15660527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:04:38  来源:igfitidea点击:

Navigationbar not displaying in UItableviewcontroller in storyboard

iosxcodeuinavigationcontrollerstoryboarduitableview

提问by Naveen

i created a UICollectionviewcontrollerview and embed a UINavigationcontrollerthen I created one button in navigation bar.Again i created one UITableviewcontrolleralso i embed one uinavigationcontrollerto it,when i click the button in UICollectionviewnavigation bar it shows the UITableviewcontrollerup to this point is fine,but after this the navigation bar in UITableviewcontroller is not showing at all.please help me

我创建了一个UICollectionviewcontroller视图并嵌入了一个UINavigationcontroller然后我在导航栏中创建了一个按钮。再次我创建了一个UITableviewcontroller我也嵌入了一个uinavigationcontroller按钮,当我点击UICollectionview导航栏中的按钮时,它显示UITableviewcontroller到目前为止是好的,但在此之后导航UITableview控制器中的栏根本没有显示。请帮助我

uitableviewcontroller image

uitableviewcontroller image

enter image description here

enter image description here

回答by Stan Cromlish

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

祝你好运

回答by barryjones

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];

回答by Paul Williams

回答by Nora Alnashwan

In addition to @barryjones solution, you can directly push a table view controller using the navigation controller.

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

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

回答by Paul Williams

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

除了上述答案之外,我还以类似的方式在 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

但是,这会造成标签栏不再可见的情况。最终通过将以下内容添加到 AppDelegate.swift 中的类来解决

var tabBarController: UITabBarController?

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

然后也在 AppDelegate 中,我修改了 didFinishLaunchingWithOptions 如下:

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