应用程序未在 Xcode 5.1.1 模拟器上运行

Posted

技术标签:

【中文标题】应用程序未在 Xcode 5.1.1 模拟器上运行【英文标题】:App not running on Xcode 5.1.1 Simulator 【发布时间】:2015-02-12 03:47:27 【问题描述】:

我是 Objective-C 的新手,我在 autoReleasepool 块中得到一个线程 1:信号 SIGBRT。

这是我的代码:我只在这两个文件中添加了代码。我还将 3 张图像导入到支持文件夹中。

ViewController.m

//
//  ViewController.m
//  TicTacToe

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController



- (void)viewDidLoad

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    oImg = [UIImage imageNamed:@"o.png"];
    xImg = [UIImage imageNamed:@"x.png"];
    // set the player to 1
    playerToken = 1;
    // update the label
   whoseTurn.text =@"X will go first!";


- (void) updatePlayerInfo
    if(playerToken == 1) 
        playerToken = 2;
        whoseTurn.text = @"Its O's turn";
        NSLog(@"playerToken = %d", playerToken);
    
    else if(playerToken == 2) 
        playerToken = 1;
        whoseTurn.text =@"Its X's turn";
        NSLog(@"playerToken = %d", playerToken);
    

-(void) resetBoard
    /// clear the images stored in the UIIMageView
    b1.image = NULL;
    b2.image = NULL;
    b3.image = NULL;
    b4.image = NULL;
    b5.image = NULL;
    b6.image = NULL;
    b7.image = NULL;
    b8.image = NULL;
    b9.image = NULL;
    // reset the player and update the label text
    playerToken= 1;
    whoseTurn.text = @"X goes first";


- (IBAction)buttonReset:(UIButton *)sender 
    [self resetBoard];


- (void)didReceiveMemoryWarning

    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

- (void)touchesBegan:(NSSet *)touches
           withEvent:(UIEvent *)event
    UITouch *touch = [[event allTouches] anyObject];
    if(CGRectContainsPoint([b1 frame], [touch
                                        locationInView:self.view]))
        if(playerToken==1) b1.image = xImg; 
        if(playerToken==2) b1.image = oImg; 
    
    if(CGRectContainsPoint([b2 frame], [touch
                                        locationInView:self.view]))
        if(playerToken==1) b2.image = xImg; 
        if(playerToken==2) b2.image = oImg; 
    
    if(CGRectContainsPoint([b3 frame], [touch
                                        locationInView:self.view]))
        if(playerToken==1) b3.image = xImg; 
        if(playerToken==2) b3.image = oImg; 
    
    if(CGRectContainsPoint([b4 frame], [touch
                                        locationInView:self.view]))
        if(playerToken==1) b4.image = xImg; 
        if(playerToken==2) b4.image = oImg; 
    
    if(CGRectContainsPoint([b5 frame], [touch
                                        locationInView:self.view]))
        if(playerToken==1) b5.image = xImg; 
        if(playerToken==2) b5.image = oImg; 
    
    if(CGRectContainsPoint([b6 frame], [touch
                                        locationInView:self.view]))
        if(playerToken==1) b6.image = xImg; 
        if(playerToken==2) b6.image = oImg; 
    
    if(CGRectContainsPoint([b7 frame], [touch
                                        locationInView:self.view]))
        if(playerToken==1) b7.image = xImg; 
        if(playerToken==2) b7.image = oImg; 
    
    if(CGRectContainsPoint([b8 frame], [touch
                                        locationInView:self.view]))
        if(playerToken==1) b8.image = xImg; 
        if(playerToken==2) b8.image = oImg; 
    
    if(CGRectContainsPoint([b9 frame], [touch
                                        locationInView:self.view]))
        if(playerToken==1) b9.image = xImg; 
        if(playerToken==2) b9.image = oImg; 
    
    [self updatePlayerInfo];

@end

ViewController.h

//
//  ViewController.h
//  TicTacToe

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController 
    // the X or O images
    IBOutlet UIImage * oImg;
    IBOutlet UIImage * xImg;
    NSInteger playerToken;

    IBOutlet UIImageView*board;
    IBOutlet UILabel    *whoseTurn;
    IBOutlet UIButton   *resetButton;


    //UIImages X's and O's
     IBOutlet UIImageView *b1;
     IBOutlet UIImageView *b2;
     IBOutlet UIImageView *b3;
     IBOutlet UIImageView *b4;
     IBOutlet UIImageView *b5;
     IBOutlet UIImageView *b6;
     IBOutlet UIImageView *b7;
     IBOutlet UIImageView *b8;
     IBOutlet UIImageView *b9;




@end

【问题讨论】:

我得到了这个:libc++abi.dylib:以 NSException 类型的未捕获异常终止 设置一个异常断点,看看能不能找出异常抛出的地方。您可以在此处了解如何执行此操作:My App Crashed, Now What? – Part 1。 2015-02-11 23:03:27.256 TicTacToe[44118:613] *** 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[ setValue:forUndefinedKey:] :此类不符合键 sd 的键值编码。 *** 首先抛出调用堆栈:( libc++abi.dylib: 以 NSException (lldb) 类型的未捕获异常终止 【参考方案1】:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[&lt;ViewController 0x109356bd0&gt; setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key sd.' ***

这通常意味着您曾经在您的文件中有一个 IBOutlet 已删除,但您忘记从您的 xib 或 Interface Builder 中的情节提要中删除连接。查找不应存在的名为 sd 的属性。

【讨论】:

以上是关于应用程序未在 Xcode 5.1.1 模拟器上运行的主要内容,如果未能解决你的问题,请参考以下文章

React Native 应用程序未在 XCode iOS 模拟器中运行

Today 小部件未在设备上启动(适用于模拟器)

iOS 今日视图未在设备上运行

Xcode 版本 5.1.1 (5B1008) - 在 iOS 7.0 而不是 7.1 上运行模拟器

Pod install 未在 Flutter 应用程序中安装 Pod

iOS 模拟器未在 Titanium Studio 中显示