【问题标题】:Navigation Controller shows black screen导航控制器显示黑屏
【发布时间】:2017-11-26 20:53:22
【问题描述】:

我在学习 iOS 开发时遇到了导航控制器的一些问题。

我创建了一个 SingleView 应用程序,然后使用“嵌入导航控制器”来获取导航控件。

我遇到的问题是,app搭建成功后,只有导航栏可见,其他UI组件都是纯黑色的。我已经在真实设备上尝试过,清理/重建,删除应用并重新构建,都得到了相同的结果。

下面是截图:

故事板截图:

当导航控制器被点击时:

我已经尝试更新约束和框架,所以没有琥珀色三角形警告。

“是初始视图控制器”已经打勾。

代码:

AppDelegate.m

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

=== 更新 ====

使用UINavigationController 而不是UIViewController 是我的错误

有关详细信息,请参阅已接受的答案。

【问题讨论】:

  • 无论您使用的是什么,您能否发布一张您的 xib/storyboard 的屏幕截图。
  • 您是否有可能重写了viewDidLoad 方法而忘记调用super?
  • @AyanSengupta thx,我已经更新了故事板的截图。
  • @dariaa thx,我刚刚确认 [super viewDidLoad]viewDidLoad 中唯一的一行
  • 只需点击 segue(VC 之间的箭头),然后按键盘上的“删除”。你会得到它删除。要重新分配,请在情节提要中选择源 VC>>按住“控制”>>拖动到情节提要上的另一个 VC 并释放>>从出现的列表中选择转场类型并设置转场。希望这可以帮助! :)

标签: ios uinavigationcontroller


【解决方案1】:

我查看了您的代码。在 ViewController.h 你有:

@interface ViewController : UINavigationController <UITableViewDelegate, UITableViewDataSource>

把它改成

@interface ViewController : UIViewController

它会出现的!

导航控制器正在尝试显示另一个空导航控制器! :)

【讨论】:

  • 谢谢。我只是尝试删除导航控制器,以便它直接进入视图控制器,但它不起作用。在我的故事板中,它没有“文件所有者”。它似乎只存在于旧版本中?
  • @ss1271 文件所有者不是一个较旧的概念,但如果您使用情节提要,则不可用。它仍然可以通过 xib 获得。
  • @P.Sami thx,我刚试过但还是不行。我已经用我的项目(.zip 文件)的链接更新了我的问题,你有时间检查一下吗?
  • @ss1271 我想你现在已经知道你错过了什么!所以我没有发布额外的东西。很高兴它有帮助:)
  • 好的,谢谢!你节省了我的时间!它发生(从 UINavigationViewController 继承)是因为在类创建向导中保存了过去继承的超类。 Xcode 只是保存你的最后一个输入,它会导致这些错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-13
  • 2011-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多