I'm using a NSTimer in a NSObject class (Timer), that fires a method, that increments a variable and fires a method in a View Controller (InfoViewController). (Confused ;-D )
Everything shows up on the screen and and the timer is started correctly. The variable f.hunger updates and shows the correct value (when using printf("%f", f.hunger) ) but the UIProgress bar doesn't update itself. f.hunger's starting value is 1.
If anyone can help me, point out where I've made an obvious mistake or got a suggestion it would be most appreciated as it's been doing my head in for a good few hours now. I've added some sample code below to show what I'm doing a bit more clearly.
Cheers everyone. :-D
Timers Class
- (void)startHungerTimer
{
if(hungerTimer.isValid == NO)
{
infoVC = [[InfoViewController alloc] init];
self.hungerTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(incrementHungerTimer:) userInfo:nil repeats:YES];
}
}
- (void)incrementHungerTimer:(NSTimer *)aTimer
{
f.hunger -= 0.01;
[infoVC updateHungerProgress];
}
Info View Controller
- (void)开发者_运维知识库updateHungerProgress
{
Functions *f = [Functions sharedFunctions];
hungerBar.progress = f.hunger;
}
- (void)loadView
{
hungerBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
[hungerBar setFrame:CGRectMake(17.0, 30.0, 160.0, 10.0)];
hungerBar.progress = f.hunger;
[bView addSubview:hungerBar];
[hungerBar release];
}
My guess, given your question and comments, is that your "hungerBar" outlet isn't connected to the progress bar in Interface Builder.
精彩评论