我想使用NSTimer從另一個訪問方法時,延遲。我的意思是,我希望movebricksdown的方法可以在幾秒鐘後被訪問,而不是立刻從我的findmatches方法中找到。在選擇器NSTimer錯誤
但是,我在@selector部件上看到了一條錯誤消息。
我用
delaymovingbrickdowntimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(movebricksdown: x Y: y Direction: Dir) userInfo:nil repeats:YES];
把延遲。
我知道它會工作,如果它說@ selector(movebricksdown),但我需要x,y和Dir值標記到movebricksdown方法。
我在做什麼錯了,當我使用
delaymovingbrickdowntimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(movebricksdown: x Y: y Direction: Dir) userInfo:nil repeats:YES];
?
ps。 X,Y和導演都是整數提前
***UPDATE
感謝* ** * ** * ** * ** * ** * ** * ** * *** 我試了一下這樣的...
//the method movebricksdown
-(void)movebricksdown: (int) x Y: (int) y Direction: (int) Dir
//The method that is called from the NSTimer statement
- (void) moveBricksDown:(NSTimer *) timer {
NSDictionary *dict = [timer userInfo]; //warning: local declaration of 'timer' hides instance variable
[self movebricksdown:[[dict objectForKey:@"x"] intValue] Y:[[dict objectForKey:@"y"] intValue] Direction:[dict objectForKey:@"Dir"]]; //warning: passing argument 3 of 'movebricksdown:Y:Direction:' makes integer from pointer without a cast
}
NSNumber *newX = [NSNumber numberWithInt:x];
NSNumber *newY = [NSNumber numberWithInt:y];
NSNumber *newDir = [NSNumber numberWithInt:Dir];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:newX, @"x", newY, @"y", newDir, @"dir", nil];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(moveBricksDown:) userInfo:dict repeats:NO];
** * **UPDATE* ** * ** * * * * ** * *
我用performselector代替它解決了它。
感謝任何方式對所有的幫助:)
'[字典objectForKey:@「風向「]'應該是'[[dict objectForKey:@」Dir「] intValue]' – 2011-05-20 07:14:35