Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS-以nib为单位显示系统时间_Ios_Objective C_Uiviewcontroller_Uilabel - Fatal编程技术网

iOS-以nib为单位显示系统时间

iOS-以nib为单位显示系统时间,ios,objective-c,uiviewcontroller,uilabel,Ios,Objective C,Uiviewcontroller,Uilabel,好的,我正在为iOS构建一个应用程序,但在UILabel中正确显示当前时间时遇到了一些问题。 以下是ViewController.h文件中的代码: @interface ViewController : UIViewController <UIApplicationDelegate> @property (strong, nonatomic) IBOutlet UILabel *timeLabelStandbyScreen; -(void)updateLabel; -(

好的,我正在为
iOS
构建一个应用程序,但在
UILabel
中正确显示当前时间时遇到了一些问题。 以下是
ViewController.h
文件中的代码:

 @interface ViewController : UIViewController <UIApplicationDelegate>

 @property (strong, nonatomic) IBOutlet UILabel *timeLabelStandbyScreen;

 -(void)updateLabel;

 -(void)updateTime;

 @end

 @interface updateTime : NSDate

 @end

我相信问题很简单,我感谢你的帮助。谢谢

注释掉preformSelector方法并添加一个NSTimer(如@rocir建议的),它会正确显示时间。

您的“preformSelector…”方法中有一个输入错误。我不确定什么不起作用。是不是因为标签不是每秒钟更新一次?您需要一个NSTimer,并像这样使用它:[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime)userInfo:nil repeats:YES];当您不再使用NSTimer时,请确保它无效。谢谢@rocir!成功了。我注释掉了preformSelector方法并添加了NSTimer,它消除了错误。添加您的答案,以便帮助所有其他人Jake先生
@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