[英]Xcode cocoa osx NSTextfield query
I created a simple maths based app. 我创建了一个简单的基于数学的应用程序。 The app asks a user 6 multiplication table questions. 该应用程序向用户询问6个乘法表问题。 eg Q1 10 x 10 The user enters an answer The app displays whether the user's answer was correct or incorrect and displays this using the following 例如Q1 10 x 10用户输入答案应用程序显示用户答案是正确还是不正确,并使用以下内容显示
IBOutlet NSTextField *CorrectIncorrect;
In a cycle of the app (1 question of 6) CorrectIncorrect is used to display the strings 'correct' or 'incorrect' using this line of code 在应用程序循环中(1个问题,共6个问题),CorrectIncorrect用于使用以下代码行显示字符串“正确”或“不正确”
[CorrectIncorrect setStringValue:receivedAnswer];
[[CorrectIncorrect window] display];
Then as the next question is posed to the user, the either string is cleared using the following code. 然后,在向用户提出下一个问题时,使用以下代码清除任一字符串。
[CorrectIncorrect setStringValue:@""];
[[CorrectIncorrect window] display];
Initially, each CorrectIncorrect string was being cleared to quickly, so the user never saw if their answer was 'correct' or 'incorrect'. 最初,每个CorrectIncorrect字符串都会被快速清除,因此用户从不会看到他们的答案是“正确”还是“错误”。 I therefore used a time delay method to slow the process in order to allow the user to see the display before it was cleared.see below 因此,我使用时间延迟方法来减慢该过程,以使用户可以在清除显示之前看到显示。请参阅下文
- (void)TimeDelay
{
startInterval = [NSDate timeIntervalSinceReferenceDate];
stopInterval = [NSDate timeIntervalSinceReferenceDate];
while ((stopInterval - startInterval) <= 1)
{
stopInterval = [NSDate timeIntervalSinceReferenceDate];
}
}
This worked fine in Xcode 5. Does not work in Xcode 7.3.1. 这在Xcode 5中工作正常。在Xcode 7.3.1中不起作用。 Any advice appreciated. 任何建议表示赞赏。
Few things: 一些事情:
1) Time interval is in seconds, so <= 1
really isn't much time, have you tried increasing that time and seeing what it looks like? 1)时间间隔以秒为单位,因此<= 1
确实不是很多时间,您是否尝试过增加时间并查看其外观?
2) You should also consider adding a button like "Go to next question". 2)您还应该考虑添加一个按钮,例如“转到下一个问题”。 That way you won't need to have a timer 这样一来,您就不需要计时器
3) If you want to have a timer to reset the string, you should just use Grand Central Dispatch 3)如果您想要一个计时器来重置字符串,则应该只使用Grand Central Dispatch
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[CorrectIncorrect setStringValue:@""];
});
one-ish line, and is more intuitive 一条直线,更直观
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.