我對Objective-C相當陌生,我在autoReleasepool塊中獲得線程1:信號SIGBRT。應用程序不在Xcode 5.1.1模擬器上運行
這是我的代碼:我只向這兩個文件添加了代碼。我還將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 [email protected]"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 [email protected]"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的未捕獲異常終止 – Manu 2015-02-12 03:48:34
設置異常斷點以查看是否可以找出引發異常的位置。你可以在這裏找到如何做到這一點:[我的應用程序崩潰,現在什麼? - 第1部分](http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1)。 – 2015-02-12 03:58:51
2015-02-11 23:03:27.256 TicTacToe [44118:613] ***終止應用程序,由於未捕獲異常'NSUnknownKeyException',原因:'[ setValue:forUndefinedKey:]:該類不是鍵值編碼符合關鍵sd'。 ***第一次擲出調用堆棧: ( libC++ abi.dylib:以NSException類型的未捕獲異常終止 (lldb) –
Manu
2015-02-12 04:04:14