我正在尝试睡一个方法(见下文),而不是textLabel从值的变化myTextLabelString,等待5秒,改为"睡5工作",等待5秒,最后改为"睡5工作第二轮" ....它只是从值开始myTextLabelString,等待10秒,然后变为"睡眠5第二次工作".
- (void)textLabelChanger:(id)sender {
NSString *myTextLabelString = [NSString stringWithFormat:@"%d", gameCountDown];
textLabel.text=myTextLabelString;
sleep(5);
textLabel.text=@"sleep 5 worked";
sleep(5);
textLabel.text=@"sleep 5 worked second time round";
return;
}
Run Code Online (Sandbox Code Playgroud) 这是问题所在:我有一些类似的代码
otherWinController = [[NotificationWindowController alloc] init];
for (int i = 0; i < 10; i++) {
[otherWinController showMessage:[NSString stringWithFormat:@"%d", i]];
NSLog(@"%d", i);
sleep(1);
}
Run Code Online (Sandbox Code Playgroud)
其他的WinController是NSWindowController的子类,我用它来更新我的窗口,因为代码中发生了更改,而alloc init方法只是打开了nib并显示了窗口.showMessage是一种更改NSTextView以显示参数中的任何文本的方法.
在NSLog中,文本每秒都会更改,只计为10.但是对于showMessage方法,文本为空整整十秒,然后只显示数字10.任何想法?
FTR,showMessage方法很简单
- (void)showMessage:(NSString *)text {
[[self message] setStringValue:text];
}
Run Code Online (Sandbox Code Playgroud)
并不重要,这是非常基本的.
我有一个关于UILabels的问题.我甚至不确定这是否正确的方法,但我试图更新UILabel以显示0到24之间的两个数字然后循环回零并再次显示数字序列.问题是,它需要每1/24秒更新一次UILabel.这是我到目前为止的代码......
-(void)viewDidLoad {
fpsTimer = [NSTimer scheduledTimerWithTimeInterval: .01 target: self selector: @selector(updateFpsDisplay) userInfo: nil repeats: YES];
}
- (void)updateFpsDisplay {
for (int i=0; i<100; i++) {
NSLog(@"%d", i%24);
[timecodeFrameLabel setText:[NSString stringWithFormat:@"0%d", i%24]];
}
}
Run Code Online (Sandbox Code Playgroud)
此代码在运行时成功打印出控制台循环中的数字1-24,但名为"timecodeFrameLabel"的UILabel只显示03并且不会更改.
有什么建议?