我有一个 NSTextField 可以根据结果重新填充自己;我想自动执行 IBAction(通常通过单击应用程序中的 NSButton 来控制)。如何根据结果自动执行点击或 IBAction?
appDelegate.h
@interface main : NSView <NSApplicationDelegate>
{
NSView *main;
IBOutlet NSTextField *textValue;
IBOutlet NSWindow* window1;
IBOutlet NSWindow* window2;
}
- (void)textUpdated;
- (IBAction)switchWindow:(id)sender;
我想触发或绑定到(IBAction)switchWindow:
appDelegate.m
- (void)textUpdated
{
[textValue setStringValue:[NSString stringWithFormat:@"%@, Switching Window", stringValue]];
[self switchWindow:sender];
}
- (IBAction)switchWindow:(id)sender {
[self performSelector:[NSApp keyWindow]==window?@selector(openWindow):@selector(closeWindow) withObject:nil afterDelay:0.0];
}
- (void)openWindow {
[window1 showWindow:window2 open:YES];
}
- (void)closeWindow {
[window2 showWindow:window1 open:NO];
}