NSTextField 在方法结束之前更新

发布于 2024-12-01 23:54:00 字数 354 浏览 0 评论 0原文

所以事情是这样的:

我有一个标签(NSTextField),我想在单击按钮后激活它。该标签将在程序加载一些 wav 时出现(因为加载时通常会产生轻微的延迟)。然后,一旦发生这种情况(并且出现新视图),我希望它消失。

现在,我遇到的问题是,当我尝试此操作时,此更新似乎没有发生。如果我不让它在最后消失,那么我就可以看到它,但只有在发生延迟之后(使其变得毫无意义)。

目前我正在使用:

[label2 setHidden:NO];

我知道一旦我调用它的方法完成(这是一个问题),就会发生这种情况。知道我可以做什么,以便在程序加载 wav 时显示标签吗?

多谢多谢!!

so here is the deal:

I have a label (NSTextField) that I want to activate after I click a button. This label will appear while the program is loading some wavs (since it usually makes a minor delay when it does). I then want it gone once this has happened (and the new View appears).

Now, the problem I have is that this update does not seem to happen when I tried this. If I don't make it disappear at the end then I can see it, but only after the delay has occured (rendering it pointless).

Currently I am using:

[label2 setHidden:NO];

I understand that this will occur once the method I called it in has finished (which is a problem). Any idea what I could do instead so that the label is shown while the program is loading wavs?

Thanks heaps!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿咻 2024-12-08 23:54:00

好吧,我想我自己解决了它 - 我希望这对人们有帮助。

因此,当我单击按钮时,我会禁用按钮并暂时替换标签。然而,这只发生在下一个视图中(所以我不确定如何使其发生在同一个视图中)。
我禁用按钮大约 1 秒钟,标签就显示在此处。

下面是一些代码来说明我的意思:

- (IBAction)clickedTheButton:(id)sender {
    [button setEnabled:NO];
    [label2 setHidden:NO];
    ...
    //Changes the View
    [self nextMethod];
}

视图现在已更改,接下来将调用此方法。这使我能够看到标签。

-(void)nextMethod{
    ...
    [self performSelector:@selector(delayedDisplay:) 
          withObject:@"Hi" 
          afterDelay:1.0]; //delay for 1 second
}

然后,此方法将它们恢复到原始状态(因此标签被隐藏,按钮被再次激活)

-(void) delayedDisplay:(NSString *)string{
    [button setEnabled:YES];
    [label2 setHidden:YES];
}

Ok, I guess I solved it myself - I hope this helps people.

So when I click the button I disable the buttons and replace the label temporarily. This, however, only happens in the next view (so I'm not sure how to make it occur in the same view).
I disable the buttons for about 1 second, and it is here that the label is shown.

Here's some code to show what I mean:

- (IBAction)clickedTheButton:(id)sender {
    [button setEnabled:NO];
    [label2 setHidden:NO];
    ...
    //Changes the View
    [self nextMethod];
}

The View has now changed, and this method is called next. This enables me to see the label.

-(void)nextMethod{
    ...
    [self performSelector:@selector(delayedDisplay:) 
          withObject:@"Hi" 
          afterDelay:1.0]; //delay for 1 second
}

This method then puts them back to their original state (so the label is hidden and the button is activated again)

-(void) delayedDisplay:(NSString *)string{
    [button setEnabled:YES];
    [label2 setHidden:YES];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文