Ios 由于未捕获异常而终止应用程序';NSInvalidArgumentException';在我的;游戏“;

Ios 由于未捕获异常而终止应用程序';NSInvalidArgumentException';在我的;游戏“;,ios,objective-c,Ios,Objective C,我在学习在线课程,并得到了股票,因为即使按照步骤(或者可能我错过了一些?)我也得到了错误。我在谷歌和这里做了几次搜索,但由于我对IOS开发还不熟悉,即使有其他人的回答,我也能理解我的问题 以下是错误: 2015-06-12 23:03:17.477 Pirate Game[6511:1193126] -[RBTile setWeapon:]: unrecognized selector sent to instance 0x78830dc0 2015-06-12 23:03:17.481 Pir

我在学习在线课程,并得到了股票,因为即使按照步骤(或者可能我错过了一些?)我也得到了错误。我在谷歌和这里做了几次搜索,但由于我对IOS开发还不熟悉,即使有其他人的回答,我也能理解我的问题

以下是错误:

2015-06-12 23:03:17.477 Pirate Game[6511:1193126] -[RBTile setWeapon:]: unrecognized selector sent to instance 0x78830dc0
2015-06-12 23:03:17.481 Pirate Game[6511:1193126] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RBTile setWeapon:]: unrecognized selector sent to instance 0x78830dc0'
*** First throw call stack:
(
0   CoreFoundation                      0x00874746 __exceptionPreprocess + 182
1   libobjc.A.dylib                     0x004fda97 objc_exception_throw + 44
2   CoreFoundation                      0x0087c705 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3   CoreFoundation                      0x007c3287 ___forwarding___ + 1047
4   CoreFoundation                      0x007c2e4e _CF_forwarding_prep_0 + 14
5   Pirate Game                         0x00014a94 -[RBFactory tiles] + 388
6   Pirate Game                         0x00011c6f -[ViewController viewDidLoad] + 143
7   UIKit                               0x00d97da4 -[UIViewController loadViewIfRequired] + 771
8   UIKit                               0x00d98095 -[UIViewController view] + 35
9   UIKit                               0x00c89e85 -[UIWindow addRootViewControllerViewIfPossible] + 66
10  UIKit                               0x00c8a34c -[UIWindow _setHidden:forced:] + 287
11  UIKit                               0x00c8a648 -[UIWindow _orderFrontWithoutMakingKey] + 49
12  UIKit                               0x00c989b6 -[UIWindow makeKeyAndVisible] + 80
13  UIKit                               0x00c2ded8 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3217
14  UIKit                               0x00c31422 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1639
15  UIKit                               0x00c4a93e __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke + 59
16  UIKit                               0x00c3004a -[UIApplication workspaceDidEndTransaction:] + 155
17  FrontBoardServices                  0x031d6c9e __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
18  FrontBoardServices                  0x031d672f __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
19  FrontBoardServices                  0x031e8d7c __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 30
20  CoreFoundation                      0x00796050 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 16
21  CoreFoundation                      0x0078b963 __CFRunLoopDoBlocks + 195
22  CoreFoundation                      0x0078b7bb __CFRunLoopRun + 2715
23  CoreFoundation                      0x0078aa5b CFRunLoopRunSpecific + 443
24  CoreFoundation                      0x0078a88b CFRunLoopRunInMode + 123
25  UIKit                               0x00c2fa02 -[UIApplication _run] + 571
26  UIKit                               0x00c33106 UIApplicationMain + 1526
27  Pirate Game                         0x000148da main + 138
28  libdyld.dylib                       0x02c00ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
所以从我的搜索中我能理解的是,我试图发送的东西不是同一类型的。我对所有3个自定义类都有相同的问题

//
//  RBFactory.m
//  Pirate Game
//
//  Created by Richard Berube on 2015-06-06.
//  Copyright (c) 2015 Richard Berube. All rights reserved.
//

#import "RBFactory.h"
#import "RBTile.h"

@implementation RBFactory

-(NSArray *)tiles{


    RBTile *tile1 = [[RBTile alloc] init];
    tile1.story = @"Captain, we need a fearless leader such as you to undertake a voyage. You must stop the evil pirate Boss before he steals any more plunder. Would you like a blunted sword to get started?";
    tile1.backgroundImage = [UIImage imageNamed:@"PirateStart.png"];
    CCWeapon *bluntedSword = [[CCWeapon alloc]init];
    bluntedSword.name = @"Blunted sword";
    bluntedSword.damage = 12;
    NSLog(@"%@", bluntedSword);
    tile1.weapon = bluntedSword;
    tile1.actionButtonName =@"Take the sword";
我使用断点进行了测试,出现了崩溃

tile1.weapon = bluntedSword;
NSLog返回:

2015-06-12 23:03:14.602 Pirate Game[6511:1193126] <CCWeapon: 0x786a6f50>
最后一个是自定义类,实际上是其中一个,因为这三个类都导致了相同的问题

//
//  CCWeapon.h
//  Pirate Game
//
//  Created by Richard Berube on 2015-06-10.
//  Copyright (c) 2015 Richard Berube. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface CCWeapon : NSObject

@property (strong,nonatomic) NSString *name;
@property (nonatomic) int damage;

@end
//
//CCH
//海盗游戏
//
//由Richard Berube于2015年6月10日创作。
//版权所有(c)2015 Richard Berube。版权所有。
//
#进口
@接口:NSObject
@属性(强,非原子)NSString*名称;
@财产(非原子)损害;
@结束
我真的很感激你的一点帮助!2天以来我一直在备货。。我可以重新开始所有的视频(在线课程),但这不会教我如何调试

也许最后有用的信息可能是我使用了Xcode 6.3.1

谢谢

更新1:最终的项目是这个

我的RBtile是github项目中的CCtile

更新2:这是我的viewcontroler

//
//  ViewController.m
//  Pirate Game
//
//  Created by Richard Berube on 2015-06-06.
//  Copyright (c) 2015 Richard Berube. All rights reserved.
//

#import "ViewController.h"
#import "RBFactory.h"
#import "RBTile.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    RBFactory *factory = [[RBFactory alloc]init];
    self.tiles = [factory tiles];
    self.character = [factory character];
    self.currentPoint = CGPointMake(0, 0);
    [self updateTile];
    [self updateButtons];
    [self updateCharacterStatsForArmor:nil withWeapons:nil withHealthEffect:0];
}

-(void)updateTile{
    RBTile *tileModel = [[self.tiles objectAtIndex:self.currentPoint.x] objectAtIndex:self.currentPoint.y];
    self.storyLabel.text = tileModel.story;
    self.backgroundImageView.image = tileModel.backgroundImage;
    self.healthLabel.text = [NSString stringWithFormat:@"%i", self.character.health];
    self.damageLabel.text = [NSString stringWithFormat:@"%i", self.character.damage];
    self.armorLabel.text = self.character.armor.name;
    self.weaponLabel.text = self.character.weapon.name;
    [self.actionButton setTitle:tileModel.actionButtonName forState:UIControlStateNormal];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)actionButtonPressed:(UIButton *)sender {

    RBTile *tile = [[self.tiles objectAtIndex:self.currentPoint.x] objectAtIndex:self.currentPoint.y];
    [self updateCharacterStatsForArmor:tile.armor withWeapons:tile.weapon withHealthEffect:tile.healthEffect];
    [self updateTile];
}

- (IBAction)northButtonPressed:(UIButton *)sender {

    self.currentPoint = CGPointMake(self.currentPoint.x, self.currentPoint.y +1);
    [self updateButtons];
    [self updateTile];
}

- (IBAction)southButtonPressed:(UIButton *)sender {

    self.currentPoint = CGPointMake(self.currentPoint.x, self.currentPoint.y -1);
    [self updateButtons];
    [self updateTile];

}

- (IBAction)eastButtonPressed:(UIButton *)sender {

    self.currentPoint = CGPointMake(self.currentPoint.x + 1, self.currentPoint.y);
    [self updateButtons];
    [self updateTile];
}

- (IBAction)westButtonPressed:(UIButton *)sender {

    self.currentPoint = CGPointMake(self.currentPoint.x - 1, self.currentPoint.y);
    [self updateButtons];
    [self updateTile];
}

- (IBAction)restartButtonPressed:(UIButton *)sender {
}

-(void)updateButtons{
    self.westButton.hidden = [self tilesExistAtPoint:CGPointMake(self.currentPoint.x -1, self.currentPoint.y)];
    self.eastButton.hidden = [self tilesExistAtPoint:CGPointMake(self.currentPoint.x+1, self.currentPoint.y)];
    self.northButton.hidden = [self tilesExistAtPoint:CGPointMake(self.currentPoint.x, self.currentPoint.y+1)];
    self.southButton.hidden = [self tilesExistAtPoint:CGPointMake(self.currentPoint.x, self.currentPoint.y-1)];
}

-(BOOL)tilesExistAtPoint:(CGPoint)point{
    if (point.y >= 0 && point.x >=0 && point.x < [self.tiles count] && point.y < [[self.tiles objectAtIndex:point.x] count]) {
        return NO;
    }
    else{
        return YES;
    }
}

-(void)updateCharacterStatsForArmor:(CCArmor *)armor withWeapons:(CCWeapon *)weapon withHealthEffect:(int)healtEffect{

    if (armor != nil ) {
        self.character.health = self.character.health - self.character.armor.health +armor.health;
        self.character.armor = armor;
    }
    else if (weapon != nil){
        self.character.damage = self.character.damage - self.character.weapon.damage + weapon.damage;
        self.character.weapon = weapon;
    }
    else if (healtEffect != 0){
        self.character.health = self.character.health + healtEffect;
    }
    else {
        self.character.health = self.character.health + self.character.armor.health;
        self.character.damage = self.character.damage + self.character.weapon.damage;
    }
}

@end
//
//ViewController.m
//海盗游戏
//
//由Richard Berube于2015-06-06创建。
//版权所有(c)2015 Richard Berube。版权所有。
//
#导入“ViewController.h”
#导入“RBFactory.h”
#导入“RBTile.h”
@界面视图控制器()
@结束
@实现视图控制器
-(无效)viewDidLoad{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
RBFactory*工厂=[[RBFactory alloc]init];
self.tiles=[工厂tiles];
self.character=[工厂字符];
self.currentPoint=CGPointMake(0,0);
[自更新];
[自我更新按钮];
[self-updateCharacterStatsForArmor:nil with Arms:nil with HealthEffect:0];
}
-(void)updateile{
RBTile*tileModel=[[self.tiles对象索引:self.currentPoint.x]对象索引:self.currentPoint.y];
self.storylab.text=tileModel.story;
self.backgroundImageView.image=tileModel.backgroundImage;
self.healthlab.text=[NSString stringWithFormat:@“%i”,self.character.health];
self.damageLabel.text=[NSString stringWithFormat:@“%i”,self.character.damage];
self.armorLabel.text=self.character.armor.name;
self.weaponLabel.text=self.character.weaponLabel.name;
[self.actionButton集合标题:tileModel.actionButtonName for状态:UIControlStateNormal];
}
-(无效)未收到记忆警告{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(iAction)操作按钮按下:(UIButton*)发送者{
RBTile*tile=[[self.tiles对象索引:self.currentPoint.x]对象索引:self.currentPoint.y];
[自更新角色STATSFORARMOR:tile.armor WITH WORLD:tile.WITH healthEffect:tile.healthEffect];
[自更新];
}
-(iAction)北键按下:(UIButton*)发送器{
self.currentPoint=CGPointMake(self.currentPoint.x,self.currentPoint.y+1);
[自我更新按钮];
[自更新];
}
-(iAction)南方按钮按下:(UIButton*)发送器{
self.currentPoint=CGPointMake(self.currentPoint.x,self.currentPoint.y-1);
[自我更新按钮];
[自更新];
}
-(iAction)EastButton按下:(UIButton*)发送器{
self.currentPoint=CGPointMake(self.currentPoint.x+1,self.currentPoint.y);
[自我更新按钮];
[自更新];
}
-(iAction)WestButton按下:(UIButton*)发送器{
self.currentPoint=CGPointMake(self.currentPoint.x-1,self.currentPoint.y);
[自我更新按钮];
[自更新];
}
-(iAction)重新启动按钮按下:(UIButton*)发送方{
}
-(无效)更新按钮{
self.westButton.hidden=[self-tileExistatPoint:CGPointMake(self.currentPoint.x-1,self.currentPoint.y)];
self.eastButton.hidden=[self-tilesExistAtPoint:CGPointMake(self.currentPoint.x+1,self.currentPoint.y)];
self.northButton.hidden=[self-tilesExistAtPoint:CGPointMake(self.currentPoint.x,self.currentPoint.y+1)];
self.southButton.hidden=[self-tilesExistAtPoint:CGPointMake(self.currentPoint.x,self.currentPoint.y-1)];
}
-(BOOL)tilexistatpoint:(CGPoint)point{
如果(point.y>=0&&point.x>=0&&point.x<[self.tiles计数]&&point.y<[self.tiles对象索引:point.x]计数]){
返回否;
}
否则{
返回YES;
}
}
-(无效)更新护甲:(CCArmor*)带武器护甲:(CCArmor*)带健康效果的武器:(智力)健康效果{
如果(装甲!=零){
self.character.health=self.character.health-self.character.armar.health+armar.health;
自我。性格。盔甲=盔甲;
}
否则,如果(武器!=零){
self.character.damage=self.character.damage-self.character.will.damage+will.damage;
自我。性格。武器=武器;
}
否则如果(healtEffect!=0){
self.character.health=self.character.health+healtEffect;
}
否则{
self.character.health=self.character.health+self.character.armor.health;
自性伤害=自性伤害+自性武器伤害;
}
}
@结束
另一更新:

我通过断点发现我的一些属性没有显示

事实上应该是这样的:


所以现在我知道,当我试图通过
tile1.武器=钝剑它不工作,因为
tile1.武器不存在。但是如果你查看我的
RBTile.h
我所有的财产都在那里

问题的根源是

[RBTile SetAnswarm:]:发送到实例0x78830dc0的选择器无法识别

那就是告诉你你的
RBTile。
//
//  CCWeapon.h
//  Pirate Game
//
//  Created by Richard Berube on 2015-06-10.
//  Copyright (c) 2015 Richard Berube. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface CCWeapon : NSObject

@property (strong,nonatomic) NSString *name;
@property (nonatomic) int damage;

@end
//
//  ViewController.m
//  Pirate Game
//
//  Created by Richard Berube on 2015-06-06.
//  Copyright (c) 2015 Richard Berube. All rights reserved.
//

#import "ViewController.h"
#import "RBFactory.h"
#import "RBTile.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    RBFactory *factory = [[RBFactory alloc]init];
    self.tiles = [factory tiles];
    self.character = [factory character];
    self.currentPoint = CGPointMake(0, 0);
    [self updateTile];
    [self updateButtons];
    [self updateCharacterStatsForArmor:nil withWeapons:nil withHealthEffect:0];
}

-(void)updateTile{
    RBTile *tileModel = [[self.tiles objectAtIndex:self.currentPoint.x] objectAtIndex:self.currentPoint.y];
    self.storyLabel.text = tileModel.story;
    self.backgroundImageView.image = tileModel.backgroundImage;
    self.healthLabel.text = [NSString stringWithFormat:@"%i", self.character.health];
    self.damageLabel.text = [NSString stringWithFormat:@"%i", self.character.damage];
    self.armorLabel.text = self.character.armor.name;
    self.weaponLabel.text = self.character.weapon.name;
    [self.actionButton setTitle:tileModel.actionButtonName forState:UIControlStateNormal];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)actionButtonPressed:(UIButton *)sender {

    RBTile *tile = [[self.tiles objectAtIndex:self.currentPoint.x] objectAtIndex:self.currentPoint.y];
    [self updateCharacterStatsForArmor:tile.armor withWeapons:tile.weapon withHealthEffect:tile.healthEffect];
    [self updateTile];
}

- (IBAction)northButtonPressed:(UIButton *)sender {

    self.currentPoint = CGPointMake(self.currentPoint.x, self.currentPoint.y +1);
    [self updateButtons];
    [self updateTile];
}

- (IBAction)southButtonPressed:(UIButton *)sender {

    self.currentPoint = CGPointMake(self.currentPoint.x, self.currentPoint.y -1);
    [self updateButtons];
    [self updateTile];

}

- (IBAction)eastButtonPressed:(UIButton *)sender {

    self.currentPoint = CGPointMake(self.currentPoint.x + 1, self.currentPoint.y);
    [self updateButtons];
    [self updateTile];
}

- (IBAction)westButtonPressed:(UIButton *)sender {

    self.currentPoint = CGPointMake(self.currentPoint.x - 1, self.currentPoint.y);
    [self updateButtons];
    [self updateTile];
}

- (IBAction)restartButtonPressed:(UIButton *)sender {
}

-(void)updateButtons{
    self.westButton.hidden = [self tilesExistAtPoint:CGPointMake(self.currentPoint.x -1, self.currentPoint.y)];
    self.eastButton.hidden = [self tilesExistAtPoint:CGPointMake(self.currentPoint.x+1, self.currentPoint.y)];
    self.northButton.hidden = [self tilesExistAtPoint:CGPointMake(self.currentPoint.x, self.currentPoint.y+1)];
    self.southButton.hidden = [self tilesExistAtPoint:CGPointMake(self.currentPoint.x, self.currentPoint.y-1)];
}

-(BOOL)tilesExistAtPoint:(CGPoint)point{
    if (point.y >= 0 && point.x >=0 && point.x < [self.tiles count] && point.y < [[self.tiles objectAtIndex:point.x] count]) {
        return NO;
    }
    else{
        return YES;
    }
}

-(void)updateCharacterStatsForArmor:(CCArmor *)armor withWeapons:(CCWeapon *)weapon withHealthEffect:(int)healtEffect{

    if (armor != nil ) {
        self.character.health = self.character.health - self.character.armor.health +armor.health;
        self.character.armor = armor;
    }
    else if (weapon != nil){
        self.character.damage = self.character.damage - self.character.weapon.damage + weapon.damage;
        self.character.weapon = weapon;
    }
    else if (healtEffect != 0){
        self.character.health = self.character.health + healtEffect;
    }
    else {
        self.character.health = self.character.health + self.character.armor.health;
        self.character.damage = self.character.damage + self.character.weapon.damage;
    }
}

@end