self.navigationController == nil

时间:2012-06-07 09:41:19

标签: iphone objective-c ios

我尝试制作一个简单的切换视图功能,但它不起作用 然后我试着看看是否分配了第二个视图并且没问题。 问题是我的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]; 

1 个答案:

答案 0 :(得分:0)

您需要从UINavigationController

呈现当前视图控制器
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:Your_Current_View_Controller];

//Now present controller in any way you want

之后你的self.navigationController将不会是nil anymoer