开关视图控制器有黑屏

时间:2015-07-21 02:37:47

标签: ios objective-c uiviewcontroller

我在IB动作中编写代码以检查条件以在同一故事板中切换视图控制器但是如果我触摸按钮则转到黑屏

这是我的代码

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

1 个答案:

答案 0 :(得分:0)

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 - >身份检查员