iOS - Display system time in nib
Okay, I am building an app for iOS and I am having some trouble with
getting the current time to display properly within a UILabel. Here is the
code in the ViewController.h file:
@interface ViewController : UIViewController <UIApplicationDelegate>
@property (strong, nonatomic) IBOutlet UILabel *timeLabelStandbyScreen;
-(void)updateLabel;
-(void)updateTime;
@end
@interface updateTime : NSDate
@end
I'm new to Obj-C and I was playing around with it to see if I could fix
the problem. Everything is fine in this file it's the .m that has the
problems.
ViewController.m:
@interface ViewController ()
@end
@implementation ViewController
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self updateLabel];
}
-(void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)updateTime
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"hh:mm"];
_timeLabelStandbyScreen.text = [dateFormat stringFromDate: [NSDate
date]];
[self preformSelector:@selector(updateTime) withObject:self
afterDelay:1.0];
}
@end
I'm sure the problem is really simple and I appreciate your help. Thanks!
No comments:
Post a Comment