【问题标题】:NSTextField validation and NSSearchField save it's value to recent history on NSButton clickNSTextField 验证和 NSSearchField 将其值保存到 NSButton 单击时的最近历史记录
【发布时间】:2012-10-03 16:26:15
【问题描述】:

我有这个设置,我的NSWinow 有两个NSSearchFileds 具有相对自动保存搜索历史,一个NSTextField 和一个NSButton

NSSearchFiled 必须自动保存搜索(当用户按“Enter”键时正常工作) NSTextField 需要验证并保存到用户首选项(通过它是 action)。

问题是,如果我关注NSSearchFiled 并单击NSButton,则字符串不会自动保存到最近,如果我关注NSTextField 并单击NSButton,则该值未经过验证和保存到用户偏好...

我已经在 NSButton 操作中尝试过这个:

// SearchF_Name is of NSSearchFiled
[SearchF_Name sendAction:SearchF_Name.action to:SearchF_Name.target];

没有运气,谷歌搜索也无济于事......你帮我吗?

【问题讨论】:

    标签: xcode cocoa nstextfield nsbutton nssearchfield


    【解决方案1】:

    在提出问题后,我尝试了“最后一个选项”......并且成功了!

    这是- (IBAction)Btn_SearchAction:(id)sender的代码

    NSResponder *firstResponder = [[NSApp keyWindow] firstResponder];
    if ([firstResponder isKindOfClass:[NSText class]] && [(NSText *)firstResponder delegate] == TextF_ResultLimit) {
        NSLog(@"SearchDelegate::Btn_SearchAction TextF_ResultLimit has focus, let's save it's value");
        [TextF_ResultLimit performClick:self];
    }
    
    NSLog(@"SearchDelegate::Btn_SearchAction SearchF_Name saving search value to recent history");
    [SearchF_Name performClick:self];
    

    【讨论】:

      猜你喜欢
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多