我创建了两个视图控制器#ifndef
和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
中的详细信息。
答案 0 :(得分:2)
如果您已在故事板中添加了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启动时,它只是实例化一个空白视图控制器。