开发者

NSTextField to update before the end of a method

开发者 https://www.devze.com 2023-04-01 02:36 出处:网络
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 loadi开发者_运维问答ng some wavs (since it usually makes

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 loadi开发者_运维问答ng 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!!


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];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消