从Xcode启动iOS模拟器,并获得黑屏,Xcode挂起,无法停止任务

我在iOS模拟器中运行我的基本iPhone应用程序时(在通过Stanford iTunes CS193p讲座时)遇到了麻烦。

我一直在寻找一段时间(谷歌和SO),但目前还找不到解决scheme。 有许多类似的错误,但解决scheme似乎并没有解决这个问题。

在Xcode中,我点击“运行”。 它编译和build立成功,启动iOS模拟器,但永远不会加载应用程序。 只有顶部的状态栏。 黑屏。

我只写了非常基本的代码(跟着讲座一起),不能解决这个问题。

为了更多地混淆事情,我在这些讲座之前写了一个Web包装器(UIWebView) ,这个工作正常。 但代码几乎没有任何区别。 我从头开始创build的所有新应用程序都会因相同的黑屏问题而失败。

如果我点击模拟器上的主页button并启动应用程序,它将显示。 但Xcode似乎并不知道发生了什么事情。

就好像Xcode已经失去了与iOS模拟器交谈的能力,并假定它正在运行(即使我退出了iOS模拟器)。 我尝试退出Xcode,并要求我停止任务。 然后它只是挂起。 所以我不得不强制重新启动Xcode。

我正在使用:OSX 10.8.2 Xcode 4.5.2 iOS模拟器6.0

任何帮助非常感谢…

CalculatorAppDelegate.h

 #import <UIKit/UIKit.h> @interface CalculatorAppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end 

CalculatorAppDelegate.m

 #import "CalculatorAppDelegate.h" @implementation CalculatorAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions (NSDictionary *)launchOptions { // Override point for customization after application launch. return YES; } - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end 

CalculatorViewController.h

 #import <UIKit/UIKit.h> @interface CalculatorViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *display; @end 

CalculatorViewController.m

 #import "CalculatorViewController.h" @implementation CalculatorViewController @synthesize display = _display; - (IBAction)digitPressed:(UIButton *)sender { NSString *digit = [sender currentTitle]; NSLog(@"digit pressed = %@", digit); } @end 

令人惊讶的是,我的工作是去iOS模拟器菜单,并按下“重置内容和设置”。

在重置模拟器之前,先进入您的项目“ project navigator ”屏幕,在general – > depoyment info屏幕下,检查主界面属性是否正确设置!

在这里输入图像说明

我是iOS应用程序开发的新手。 我从一开始就开始开发iOS应用程序,在运行一个非常基本的Hello World应用程序时,也遇到了同样的问题,在iOS模拟器中构build和运行应用程序后,只出现黑屏。 不知怎的,虽然努力找出问题的解决scheme,我不小心在iOS模拟器中点击窗口 – >规模 – > 50%,它确实解决了我的问题。 然后,我可以看到我的应用程序的主页,并点击应用程序图标我能够成功地运行我的应用程序。 应用程序版本:Xcode 5.1 iOS模拟器:7.1 OSX:10.9.3

另一个解决scheme是,如果您在Objective C项目中以编程方式构buildUI,那么您可能需要添加一些代码来使视图膨胀,因此您需要添加这3行以使窗口界面与代码交互(外部2实际上是与代码交互,另一个将屏幕更改为白色,所以你会知道它的工作原理)。

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. ... self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; } 

这可能是由于没有设置正确的部署信息。 (即如果你的故事板没有设置为主界面)

解决scheme1:您可以Quit simulator然后重试。

解决scheme2 (推荐):转到iOS Simulator – > Reset Content and Settings...

步骤1

这会popup一个警告,提示'Are you sure you want to reset the iOS Simulator content and settings?'

第2步

如果您想要selectResetDon't Resetbutton。

请注意,一旦你重置模拟器的内容,所有安装在模拟器上的应用程序将被删除,它将重置为初始设置。

如果你应该放弃在Storyboard中的入口点,或者只是想改变入口点,你可以在Interface Builder中指定。 要设置新的入口点,您必须先决定哪个ViewController将作为新的入口点,并在Attribute Inspector中selectInitial Scenecheckbox。

你可以试试: http : //www.scott-sherwood.com/ios-5-specifying-the-entry-point-of-your-storyboard/

我已经设法find这个修复。 这是发现这个博客文章的礼貌:

http://vandadnp.wordpress.com/2012/03/18/xcode-4-3-1-cannot-attach-to-ios-simulator/

解决方法是按cmd + shift +,(命令,移位,然后逗号“,”)..加载一些选项释放或debugging。

将debugging器从LLDB更改为GDB。 这解决了这个问题。

要确定它是一个模拟器的问题,看看你是否可以用一个全新的项目连接到模拟器,而不需要改变任何代码。 试试标签栏模板。

如果您认为这是模拟器问题,请按下iOS模拟器菜单。 select“重置内容和设置…”。 按“重置”。

我看不到你的XIB和你在Interface Builder中连接了哪些@properties,但也可能是你没有加载你的窗口,或者你的窗口没有加载你的视图控制器。

重新启动计算机应该是你需要做的。

我有Xcode相同的问题…在启动应用程序的黑屏,没有debugging和点击将lockingXcode。

我终于find了问题…继模拟器无法连接到Xcode的领导我看了看我的etc / hosts文件,发现几个月前解决了一个不同的问题,我编辑了主机文件来映射本地主机到我的固定的IP而不是默认的…我的价值:

10.0.1.17 localhost

这应该工作,因为这是我的IP,但将其更改回默认的IP固定Xcode …

127.0.0.1 localhost

希望这可以帮助。

我正在做什么道格build议(“重置内容和设置”),但它需要很多时间,这真的很烦人…直到我最近发现完全意外的另一个解决scheme,更快,似乎也工作到目前为止! 只需在模拟器上点击cmd + L,或进入模拟器菜单“硬件 – >locking”,locking屏幕,当你解锁屏幕的应用程序工作,就像什么都没有发生:)

发生在我身上的是类的types不UIViewController附加到我的视图控制器的脚本。 这是一个UITabController …..我错误地迅速创build了错误types的类….所以确保类,如果正确的types..希望这可以帮助别人。 我很匆忙,犯了这个错误。

只需点击模拟器 – >重置内容和设置重置您的模拟器。

你也可以去硬件 – >重启,然后硬件 – >首页,并点击你的应用程序