objective-c - OSX Cocoa - 如何测试多个 NSTextField 中的更改

标签 objective-c cocoa osx-mountain-lion nstextfield

我正在尝试测试某些 NSTextField 中的更改。

我正在使用:

- (void)controlTextDidEndEditing:(NSNotification *)notification {

    if ([notification object] == field1) 
        NSLog(@"field1: stringValue == %@", [field1 stringValue]);

    if ([notification object] == field2) 
        NSLog(@"field2: stringValue == %@", [field2 stringValue]);

    if ([notification object] == field3)
        NSLog(@"field3: stringValue == %@", [field3 stringValue]);

}

这可行,但我想知道是否有更好的方法。谢谢

最佳答案

这很好。

field1 等我希望成为销售点。

您可以做得更好:

- (void)controlTextDidEndEditing:(NSNotification *)notification {

    if ([notification object] == field1) 
        NSLog(@"field1: stringValue == %@", [field1 stringValue]);

    else if ([notification object] == field2) 
        NSLog(@"field2: stringValue == %@", [field2 stringValue]);

    else if ([notification object] == field3)
        NSLog(@"field3: stringValue == %@", [field3 stringValue]);

}

关于objective-c - OSX Cocoa - 如何测试多个 NSTextField 中的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16881758/

相关文章:

ios - 读取字典元素的预期方法在 'id<NSFastEnumeration,NSObject>' 类型的对象上找不到

objective-c - iPad 应用程序偏移 20 像素

objective-c - 如何从 Objective-C 访问 Swift 中的枚举?

macos - 如果原始目录不存在,将创建目录的别名

macos - 在 Mac OS mountain lion 上设置 Subversion Server(可以通过浏览器访问,但无法从 subversion 结帐)

objective-c - 如何获取所有 mime 类型 Google Drive Api IOS

objective-c - 如何解决? 'NSProgressIndicator'之前预期的说明符限定符列表

cocoa - 如何在 Cocoa 打印对话框中获取 "Page Attributes"选项?

objective-c - Objective-C 和 Cocoa 中局部 BOOL 变量的命名约定

Python Dtrace 已打补丁,但仍然得到 "invalid probe specifier"运行测试脚本