cha*_*479 2 cocoa objective-c nstextfield
这是问题所在:我有一些类似的代码
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)
并不重要,这是非常基本的.
如果你明确地给运行循环一些时间运行,你可以在循环内部达到预期的效果:
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow: 0.1]];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1757 次 |
| 最近记录: |