I've been having alot of problems creating a timer for a iphone application, currently I have a label displaying my timer, but it is just displaying the variable i (2700) in the label, and not decreasing by one every second. Its really driving my head in as this is really my 1st attempt coding in obj C, and for the life of me I cannot get it to decrease in the label.
I was hoping one of the programs on this site would be able to readover my code (MainViewController.m), with particular reference to the timer (countDown and viewDidLoad) and help me fix my problem.
Cheers in advance.
#import "MainViewController.h"
#include <unistd.h>
#include <stdio.h>
int i = 2700;
@implementation MainViewController
@synthesize window;
@synthesize InformationAboutRSI, mainView;
- (IBAction) InformationAboutRSI {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.rsi.org.au/what-is-rsi.html"]];
}
-(void)countDown {
if (i > 0) {
i--;
countdownLabel.text = [NSString stringWithFormat:@"%i",i];
sleep(100);
}
}
- (void)viewDidLoad {
int countDown();
[countdownLabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:128.0]];
countdownLabel.text = [NSString stringWithFormat:@"%i",i];
[super viewDidLoad];
}
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)showInfo:(id)sender {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)dealloc {
[window release];
[super dealloc];
}
-(void)updateLabel {
countdownLabel.text = [NSString stringWithFormat:@"%i",i];
}
@end