簡體   English   中英

開關視圖控制器有黑屏

[英]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中設置ViewController StoryBoard ID->身份檢查器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM