我创建了两个视图控制器ViewControllerOne
和DetailViewController
。然后我对UIButton
进行了操作,当按下按钮时,它将转到第二个视图控制器,
- (IBAction)loginButtonPressed:(UIButton *)sender {
self.loginButton.hidden= YES;
self.aview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"authentication.png"]];
LAContext* context = [[LAContext alloc]init];
NSError* error = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"Authenticate with Touch ID" reply:^(BOOL success, NSError*error){
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
self.loginButton.hidden= NO;
self.aview.backgroundColor = [UIColor clearColor];
DetailViewController* detailViewController = [[DetailViewController alloc]init];
[self presentViewController:detailViewController animated:YES completion:nil];
}); }
但它给了错误,
<ViewController: 0x7f97e9da7d60> whose view is not in the window hierarchy!
当按下按钮时,其移至
DetailViewController
,但屏幕为黑色,其未在DetailViewController
中显示详细信息。 最佳答案
如果您已在Storyboard中添加了DetailViewController,则在实例化时可能必须从情节提要中引用相同的内容。UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"your_storyboard_name" bundle: nil];
DetailViewController *detailViewController = (DetailViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"your_storyboard_identifier"];
[self presentViewController:detailViewController animated:YES completion:nil];
当您使用alloc / init初始化时,它只是实例化一个空白视图控制器。
关于ios - 警告-其 View 不在IOS 9的窗口层次结构中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33140441/