这是我的代码
- (void)updateCounterImage:(NSTimer *)theTimer
{
static int count = 0;
count += 1;
int crb = 6 - count;
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"ipad_game_timer_digit-%d.png", crb]];
if ( count == 6)
[timer release];
[countTime setImage:image];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
correctLevel.hidden = YES;
incorrectLevel.hidden = YES;
incorrectAnswer.hidden = YES;
correctAnswer.hidden = YES;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:@selector(updateCounterImage:)
userInfo:nil
repeats:NO];
}
#import <UIKit/UIKit.h>
@interface GameController : UIViewController
{
IBOutlet UIImageView *countTime;
NSTimer *timer;
}
@end
问题是我的imageView没有更改其图像以供使用。
答案 0 :(得分:1)
您已在repeats
中将NO
设置为scheduledTimerWithTimeInterval
,这意味着计时器只会勾选一次。
答案 1 :(得分:1)
你应该写
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:@selector(updateCounterImage:)
userInfo:nil
repeats:YES];