iphone - self.navigationController == 无

标签 iphone objective-c ios

我尝试做一个简单的切换 View 功能但是没有用 然后我尝试查看是否分配了第二个 View 并且没问题。 问题是我的 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]; 

最佳答案

您需要从 UINavigationController 中呈现当前 View Controller

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

//Now present controller in any way you want

在那之后你的 self.navigationController 将不再是 nil

关于iphone - self.navigationController == 无,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10929335/

相关文章:

iphone - Google Places API 响应状态 "Request_Denied"

iphone - iOS 中的动画文本

iphone - 如何在关闭相机选择器之前拍摄多张照片

c - 获取协议(protocol)中方法 block 的 NSMethodSignature

ios - XCTestCase 不支持项目类

ios - Xcode - "Could not launch <AppName>” ,没有那个文件或目录错误

iphone - 从其他 View Controller 更改 UIView(在 Nib 内)背景

ios - 设置为不重复时在 iOS 中重复背景

objective-c - 带 NSOpenGLView 的 OpenGL 3.2

ios - 目标 zip : Store content when unzip file (iOS)