So I have a button that is attached to an action called writeToFile:
The action opens an NSPanel and allows the user to enter the name of the file they want to write to their desktop.
The problem I am having is I can't update the user and let them know that the write was successful before the NSPanel closes.
So I put a label or NSTextField because I am talking about a mac app inside the NSPanel and the NSTextField updates and tells the user that the write was a success.
I change the button title that is attached to the action writeToFile: to "close" and I am trying to change the method the button actually calls by using performSelector:
However, I keep getting an "Unrecognized selector"
Here is some code, any and all help is greatly appreciated:
- (void) closePanel {
[theSheet close];
}
- (IBAction) writeToFile: (id)sender
{
if ([_nameOfFile.stringValue length] > 0) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0]stringByAppendingPathComponent:_nameOfFile.stringValue];
NSString *string = _inputTextView.string;
BOOL OK = [string writeToFile:path
atomically:YES
encoding:NSUTF8StringEncoding
error:NULL];
if (OK) {
_statusField.stringValue = @"File written to desktop";
_writeButton.title = @"close";
[_writeButton performSelector:@selector(closePanel)];
} else {
_statusField.stringValue = @"Sorry, something went wrong :(";
}
} else {
_statusField.stringValue = @"Please name the file first!";
}
}