1

我尝试制作一个简单的切换视图功能,但它不起作用,然后我尝试查看是否分配了第二个视图并且它很好。问题是我self.navigationControlernil。我该如何解决?

ViewController2 *hs=[self.storyboard instantiateViewControllerWithIdentifier:@"Highscore"];
if(self.navigationController==nil)
{

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"YOur Message" message:@"Your description"
                                                   delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
    [alert show];
}


    [self.navigationController pushViewController:hs animated:YES]; 
4

1 回答 1

0

您将需要从 UINavigationController 呈现当前视图控制器

UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:Your_Current_View_Controller];

//Now present controller in any way you want

之后,您的 self.navigationController 将不再为零

于 2012-06-07T09:44:53.207 回答