简体   繁体   中英

switch view controller has a black screen

I write code in IB action to check condition to switch view controller in same story board but if I touch button it go to black screen

this is my code

-(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];
    }
}    

don't forget to set ViewController StoryBoard Id in StoryBoard -> identity inspector

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM