所以我有一个附加到名为writeToFile的动作的按钮:
该操作将打开NSPanel,并允许用户输入要写入其桌面的文件的名称。
我遇到的问题是我无法更新用户并让他们知道在NSPanel关闭之前写入成功。
所以我放了一个标签或NSTextField,因为我在讨论NSPanel中的一个mac应用程序和NSTextField更新并告诉用户写入是成功的。
我将附加到动作writeToFile的按钮标题更改为“关闭”,我试图通过使用performSelector更改按钮实际调用的方法:
但是,我不断收到“无法识别的选择器”
以下是一些代码,非常感谢任何和所有帮助:
- (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!";
}
}
答案 0 :(得分:1)
那是因为_writeButton
没有实现-closePanel
。你的班级呢。将其更改为:
[ self closePanel ];
答案 1 :(得分:0)
更改行:
[_writeButton performSelector:@selector(closePanel)];
有:
[_writeButton addTarget:self action:@selector(closePanel)forControlEvents:UIControlEventTouchUpInside];
答案 2 :(得分:0)
您是否设置了代理人?
[_writeButton setTarget:self];
[_writeButton setAction:@selector(writeToFile:)];