【发布时间】: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