ios - 切换 View 会使应用程序崩溃

标签 ios cocoa-touch uiview

这是一个非常奇怪的问题。

我包含下一个 View 的 .h 文件:

#import "MainGame.h"

当我按下屏幕时,我有这个代码来切换房间:

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    MainGame *newview = [[MainGame alloc] initWithNibName:@"MainGame" bundle:nil];
    newview.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:newview animated:YES completion:NULL];
}

而且它在 iOS 5 模拟器中运行良好;但是当我在运行 iOS 4.2 的 iPod 上测试它时,它总是崩溃。

我所有的 IBOutlets 都已正确连接,一切如我所说,它在模拟器中工作正常,但在我的 iPod 上却不行。

我以前在我的 iPod 上使用过每个单独的 View ,所以我没有使用任何需要 iOS 5 或任何东西的功能;只是这段切换 View 的代码不起作用。

我错过了什么吗?

谢谢!

最佳答案

我认为是版本问题

[self presentViewController:newview animated:YES completion:NULL];

在 iOS 4.2 中不存在,但在 iOS 5 中存在

试试这个

[self presentModalViewController:newview animated:YES];

关于ios - 切换 View 会使应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12571545/

相关文章:

ios - 如何快速更改 Controller View 某些部分的颜色?

ios - 延迟 : Swift 3 从 SuperView 中删除 View

iPhone:如何允许在自定义单元格的表格 View 中进行多项选择?

ios - 如何以编程方式打开和关闭后台获取

ios - 如何从选项卡栏 Controller 访问 subview Controller

ios - 为什么 KVO 不能在 UIView 子类上工作?

ios - XCode7/Swift 无法识别的选择器发送到实例?

iphone - NSDateFormatter——没有得到正确的格式化程序字符串

ios - 你如何在 ios 中创建无限滚动轮播?

ios - 顶部带有 UIViews 的滚动 Collection View ?