在我的應用程序中,我有一個可以在屏幕上滾動的動畫。我的問題是,當我使用@selector
來調用我的動畫時,線程崩潰。`發送給實例的無法識別的選擇器'
如果我用同樣的@selector
打電話給我的網頁另一個函數它完美的作品,但是當調用這個函數它似乎並沒有工作。如果我把我的代碼放在viewDidLoad
部分,它可以正常工作。
我嘗試了不少這些鏈接爲unrecognized selector sent to instance
在#1,但沒有任何幫助。我也試過- (void)imageSpawn
代替- (void) imageSpawn:(id)sender withEvent:(UIEvent *)
事件和選擇更改爲(imageSpawn)
,而不是`(ImageSpawn :)仍然沒有運氣....
- (void)viewDidLoad {
[self performSelector:@selector(imageSpawn:) withObject:nil afterDelay:3];
}
- (void) imageSpawn:(id) sender withEvent:(UIEvent *) event
{
UIImage* image = [UIImage imageNamed:@"ae"];
UIImageView *rocket = [[UIImageView alloc] initWithImage:image];
rocket.frame = CGRectMake(-25, 200, 25, 40);
[UIView animateWithDuration:5 animations:^(){rocket.frame=CGRectMake(345, 200, 25, 40);} completion:^(BOOL finished){if (finished){
//trigger an event.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Tapped row!"
message:[NSString stringWithFormat:@"Shot"]
delegate:nil
cancelButtonTitle:@"Yes, I did!"
otherButtonTitles:nil];
[alert show];
}
}];
[myScrollView addSubview:rocket];
}
2013-03-28 10:14:31.661 shotplacementgiude001[16897:c07] -[SelectedCellViewController imageSpawn:]: unrecognized selector sent to instance 0xa159480
2013-03-28 10:14:31.663 shotplacementgiude001[16897:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SelectedCellViewController imageSpawn:]: unrecognized selector sent to instance 0xa159480'
*** First throw call stack:
(0x16b4012 0x13c1e7e 0x173f4bd 0x16a3bbc 0x16a394e 0xdbf5b3 0x1673376 0x1672e06 0x165aa82 0x1659f44 0x1659e1b 0x27157e3 0x2715668 0x305ffc 0x2c3d 0x2b65 0x1) libc++abi.dylib: terminate called throwing an exception
(lldb)
實際上@ peko的回答(現在刪除)非常正確,對於帶有2個參數的方法你不能使用'performSelector:withObject:afterDelay:'。 – 2013-03-28 09:11:10