これを投稿する前によく検索し、多くの解決策を試しましたが、うまくいきませんでした。コードに問題がある可能性があります。これは基本的にサイコロ アプリです。ロール ボタンを押すと、ビュー内の画像がアニメーション化されますが、arc4random() の結果である NSNumber パラメータを使用して次のメソッドを呼び出すことになっている NSTimer に問題があります。そしてそれは選ばれたサイコロの実像を示しています
`
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize firstDie;
@synthesize secondDie;
@synthesize animation;
- (IBAction)rollButtonClick:(id)sender {
NSNumber* roll1 =[[NSNumber alloc] initWithInt:[self.model getDiceRoll]];
NSNumber* roll2 =[[NSNumber alloc] initWithInt:[self.model getDiceRoll]];
[self.firstDie randDie];
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:roll1,@"Roll1Key",nil];
NSArray *info = [[NSArray alloc] initWithObjects:roll1, nil];
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showDie:) userInfo:info repeats:NO];
NSString *sum = [[NSString alloc] initWithFormat: @"Sum = %d",[roll1 intValue]+[roll2 intValue]];
self.sumLabel.text = sum;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.model = [[Model alloc]init];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end`
showDie
-(void) showDie:(NSTimer*)num
{
if (self.dieImage == nil)
{
self.dieImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 90, 90)];
[self addSubview:self.dieImage];
}
NSNumber *userInfo = num.userInfo;
NSString *filename = [[NSString alloc] initWithFormat:@"dice%d.png", [userInfo intValue]];
self.dieImage.image = [UIImage imageNamed:filename];}
ランドダイ
-(void) randDie
{
if (self.dieImage == nil)
{
self.dieImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 90, 90)];
[self addSubview:self.dieImage];
}
UIImage *dieOne = [UIImage imageNamed:@"dice1.png"];
UIImage *dieTwo = [UIImage imageNamed:@"dice2.png"];
UIImage *dieThree = [UIImage imageNamed:@"dice3.png"];
UIImage *dieFour = [UIImage imageNamed:@"dice4.png"];
UIImage *dieFive = [UIImage imageNamed:@"dice5.png"];
UIImage *dieSix = [UIImage imageNamed:@"dice6.png"];
NSArray *animate = [NSArray arrayWithObjects: dieFive,dieThree,dieOne,dieFour,dieSix,dieTwo, nil];
self.dieImage.image = [UIImage animatedImageWithImages:animate duration:0.8];}
アプリが動作し、firstDie の画像が変化し続けます (2 秒間だと思います)。 その後、アプリが停止し、パラメーターを showDie に渡すと、「認識されないセレクターがインスタンスに送信されました」という問題が発生します。多分私はそれを解決する方法を理解していませんでした(私はMacの世界と客観的Cに不慣れです)助けてください。
エラーメッセージ:
2013-07-25 02:13:40.550 テスト [3166:c07] -[ViewController showDie:]: 認識されないセレクターがインスタンス 0x8827830 に送信されました
2013-07-25 02:13:40.551 test[3166:c07] *キャッチされない例外 'NSInvalidArgumentException' が原因でアプリを終了しています。理由: '-[ViewController showDie:]: 認識されないセレクターがインスタンス 0x8827830 に送信されました'
* First throw call stack: (0x1c93012 0x10d0e7e 0x1d1e4bd 0x1c82bbc 0x1c8294e 0xb192c0 0x1c52376 0x1c51e06 0x1c39a82 0x1c38f44 0x1c38e1b 0x1bed7e3 0x1bed668 0x14ffc 0x252d 0x2455 0x1) libc++abi.dylib: terminate called throwing an exception