首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从Xcode启动iOS模拟器,出现黑屏,随后Xcode挂起,无法停止任务

从Xcode启动iOS模拟器,出现黑屏,随后Xcode挂起,无法停止任务
EN

Stack Overflow用户
提问于 2013-02-03 09:09:01
回答 31查看 142.9K关注 0票数 94

我在iOS模拟器中运行基本的iPhone应用程序(在学习斯坦福大学的iTunes CS193p课程时)遇到了问题。

我已经搜索了一段时间( Google和SO),但到目前为止还没有找到解决方案。有许多类似的but,但解决方案似乎不能解决这个问题。

在Xcode中,我点击"run“。它成功编译和构建,启动iOS模拟器,但它从未加载应用程序。仅显示顶部的状态栏。有一个黑屏。

我只写了非常基本的代码(跟随讲座),无法解决这个问题。

更令人困惑的是,在这些讲座之前,我编写了一个web包装器(UIWebView),它工作得很好。但在代码中几乎没有任何区别。我从头开始创建的所有新应用都会因为同样的黑屏问题而失败。

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

这就好像Xcode已经失去了与iOS模拟器对话的能力,并假定它正在运行(即使我退出了iOS模拟器)。我尝试退出Xcode,它要求我停止任务。然后它就挂了。所以我必须强制重启才能退出Xcode。

我使用的是: OSX 10.8.2 Xcode 4.5.2 iOS模拟器6.0

CalculatorAppDelegate.h

代码语言:javascript
复制
#import <UIKit/UIKit.h>

@interface CalculatorAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

CalculatorAppDelegate.m

代码语言:javascript
复制
#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 active 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

代码语言:javascript
复制
#import <UIKit/UIKit.h>

@interface CalculatorViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *display;

@end

CalculatorViewController.m

代码语言:javascript
复制
#import "CalculatorViewController.h"

@implementation CalculatorViewController

@synthesize display = _display;

- (IBAction)digitPressed:(UIButton *)sender
{
    NSString *digit = [sender currentTitle];
NSLog(@"digit pressed = %@", digit);
}

@end
EN

回答 31

Stack Overflow用户

回答已采纳

发布于 2013-07-12 23:37:54

令人惊讶的是,我的工作是转到iOS模拟器菜单,并按下“重置内容和设置”。(在iOS 13中,它在硬件下)

票数 106
EN

Stack Overflow用户

发布于 2014-01-22 17:16:32

在重置仿真器之前,首先转到您的项目“项目导航器”屏幕,并在常规->部署信息屏幕下检查主界面属性是否正确设置!

票数 44
EN

Stack Overflow用户

发布于 2019-07-14 19:06:52

如果您使用的是SwiftUI

如果您要从以前版本的Xcode11进行更新,则对SceneDelegate willConnectTo session: options connectionOptions初始化有一些更改:

window现在使用UIWindow(windowScene: windowScene)进行初始化,以前的主use是UIWindow(frame: UIScreen.main.bounds)

在以前的版本中:

代码语言:javascript
复制
    let window = UIWindow(frame: UIScreen.main.bounds)
    window.rootViewController = UIHostingController(rootView: ContentView())
    self.window = window
    window.makeKeyAndVisible()

在新版本中:

代码语言:javascript
复制
    if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = UIHostingController(rootView: ContentView())
        self.window = window
        window.makeKeyAndVisible()
    }
票数 17
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14668445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档