切换视图控制器有黑屏

switch view controller has a black screen

我在 IB 操作中编写代码来检查在同一故事板中切换视图控制器的条件,但如果我触摸按钮,它会进入黑屏

这是我的代码

-(IBAction)Buyvoyage{
if (ck==1) {
    NSLog(@"brought IAP");
    VoyageplayViewController *voy = [[VoyageplayViewController alloc]init];
        [self presentViewController:voy animated:YES completion:NULL];        
}
}
try replacing  
 [self presentViewController:voy animated:YES completion:NULL];  
with  
** [self presentViewController:voy animated:YES completion:nil];**  

However, i would prefer you to use seuge by following below steps.  

 1. Create segue from each UIButton to the corresponding UIViewControllers, set Segue identifier in IB by selecting the segue(s) you just created e.g. if you have 2 button then set identifier of the Segue "TestSegue1" and "TestSegue2" respectively.  
 2. Now create an IBaction for UIButton from which you want to navigate, and put below code in that IBAction
 3. Remember to set Tag property in IB of all the UIButton(s) you want to perform navigation on as per your requirement     

// When any of my buttons is pressed, push the next UIViewController using performSeugeWithIdentifier method

- (IBAction)buttonPressed:(UIButton*)sender
{  
    if (sender.tag==1) {  
        [self performSegueWithIdentifier:@"TestSegue1" sender:sender];  
    }
    else if(sender.tag==2) 
        [self performSegueWithIdentifier:@"TestSegue2" sender:sender];
}

Or Use storyboard identifier to present your viewcontroller using below code  

- (IBAction)buttonPressed:(UIButton*)sender
{     
    //Get StoryBoard Identifier using
    UIStoryboard *storyboard = [self storyboard]; 
    if(ck==1) {
        VoyageplayViewController *voyVC = [storyboard instantiateViewControllerWithIdentifier:@"Voyage"];
        [voyVC setModalPresentationStyle:UIModalPresentationFullScreen];
        [self presentModalViewController:voyVC  animated:YES];
    }
}    

不要忘记在 StoryBoard -> identity inspector

中设置 ViewController StoryBoard Id