如何以编程方式打开一个NSComboBox的列表? [英] How to programmatically open an NSComboBox's list?

查看:188
本文介绍了如何以编程方式打开一个NSComboBox的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这一段时间..我认为这应该是一个容易的任务,但它不是= D

I've been around this for a while.. I thought this should be an easy task, but it isn't =D

我试图do,是当用户单击组合框但不特别在按钮中时显示组合框的列表。

What I am trying to do, is to display the combobox's list when the user clicks the combobox but not specifically in the button.

任何想法?
提前感谢!

Any Idea? Thanks in advance!

推荐答案

这个答案符合问题的标题, Omer想触摸一个文本字段,并有框弹出。

This answer fits the title of the question, but not question itself. Omer wanted to touch a text field and have the box popup.

此解决方案显示用户输入文本时的弹出窗口。

This solution shows the popup when the user enters text.

href =http://stackoverflow.com/users/98077/jens-alfke> Jens Alfke 。我在这里转发他的代码。感谢Jens。

I found this answer on cocoabuilder from Jens Alfke. I reposted his code here. Thanks Jens.

original cocoabuilder post:(http://www.cocoabuilder.com/archive/cocoa)

@interface NSComboBox (MYExpansionAPI)
@property (getter=isExpanded) BOOL expanded;
@end

@implementation NSComboBox (MYExpansionAPI)

- (BOOL) isExpanded
{
    id ax = NSAccessibilityUnignoredDescendant(self);
    return [[ax accessibilityAttributeValue:
                NSAccessibilityExpandedAttribute] boolValue];
}

- (void) setExpanded: (BOOL)expanded
{
    id ax = NSAccessibilityUnignoredDescendant(self);
    [ax accessibilitySetValue: [NSNumber numberWithBool: expanded]
                 forAttribute: NSAccessibilityExpandedAttribute];
}



我使用这个代码在 controlTextDidChange: code>方法。

I used this code in my controlTextDidChange: method.

- (void) controlTextDidChange:(NSNotification *) aNotification {
  NSTextField *textField = [aNotification object];
  NSString *value = [textField stringValue];
  NSComboBox *box = [self comboBox];
  if (value == nil || [value length] == 0) {
    if ([box isExpanded]) { [box setExpanded:NO]; }
  } else {
    if (![box isExpanded]) { [box setExpanded:YES]; }
  }
}

这篇关于如何以编程方式打开一个NSComboBox的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆