我对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