UIViewController 默认背景是黑色的吗?
Is UIViewController's default background black?
我创建了这个简单的演示。主要故事板是这样的:
该视图控制器中的代码如下:
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonClicked:(id)sender {
SecondViewController* secondVC = [SecondViewController new];
[self.navigationController pushViewController:secondVC animated:YES];
}
@end
在 appdelegate.m 中有:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}
在 SecondViewController.m 中,除了默认代码外什么都没有。
问题是,SecondViewController 显示为黑色,并且在推送动画时有明显的延迟。但是,当我将 SecondViewController 的 backgroundColor 设置为任何颜色(例如红色)时,没有延迟,一切看起来都很正常。我正在 iOS 8 上测试这个,在模拟器和 iPhone 设备上都是这样。
我以前从未见过这个。 UIViewController 的默认背景是透明的还是黑色的?或者我在这里错过了什么?提前致谢!
SecondViewController
没有笔尖。首先将视图控制器添加到故事板并转到 xcode(右面板)中的实用程序 -> 身份检查器(第三个图标),在这里将其 class 名称设置为 SecondViewController
和故事板 ID "SecondViewController",然后将按钮点击事件更改为:
- (IBAction)buttonClicked:(id)sender
{
SecondViewController * secondVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
[self.navigationController pushViewController:secondVC animated:YES];
}
如果你的控制器在情节提要中,可能是这一行出了问题
SecondViewController* secondVC = [SecondViewController new];
此处您正在执行 alloc init
,除非您重写 init
方法,否则不会完全初始化 SecondViewController
。如果您的 SecondViewController
在故事板中,请使用 instantiateViewControllerWithIdentifier
SecondViewController* secondVC = [self.storyboard instantiateViewControllerWithIdentifier: @"SecondViewController"];
[self.navigationController pushViewController:secondVC animated:YES];
我创建了这个简单的演示。主要故事板是这样的:
该视图控制器中的代码如下:
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonClicked:(id)sender {
SecondViewController* secondVC = [SecondViewController new];
[self.navigationController pushViewController:secondVC animated:YES];
}
@end
在 appdelegate.m 中有:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}
在 SecondViewController.m 中,除了默认代码外什么都没有。
问题是,SecondViewController 显示为黑色,并且在推送动画时有明显的延迟。但是,当我将 SecondViewController 的 backgroundColor 设置为任何颜色(例如红色)时,没有延迟,一切看起来都很正常。我正在 iOS 8 上测试这个,在模拟器和 iPhone 设备上都是这样。
我以前从未见过这个。 UIViewController 的默认背景是透明的还是黑色的?或者我在这里错过了什么?提前致谢!
SecondViewController
没有笔尖。首先将视图控制器添加到故事板并转到 xcode(右面板)中的实用程序 -> 身份检查器(第三个图标),在这里将其 class 名称设置为 SecondViewController
和故事板 ID "SecondViewController",然后将按钮点击事件更改为:
- (IBAction)buttonClicked:(id)sender
{
SecondViewController * secondVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
[self.navigationController pushViewController:secondVC animated:YES];
}
如果你的控制器在情节提要中,可能是这一行出了问题
SecondViewController* secondVC = [SecondViewController new];
此处您正在执行 alloc init
,除非您重写 init
方法,否则不会完全初始化 SecondViewController
。如果您的 SecondViewController
在故事板中,请使用 instantiateViewControllerWithIdentifier
SecondViewController* secondVC = [self.storyboard instantiateViewControllerWithIdentifier: @"SecondViewController"];
[self.navigationController pushViewController:secondVC animated:YES];