Ome*_*mer 7 cocoa objective-c nscombobox
我已经有一段时间了.我认为这应该是一件容易的事,但不是= D
我想要做的是,当用户点击组合框时显示组合框的列表,但不是在按钮中特别显示.
任何的想法?提前致谢!
这个答案符合问题的标题,但不是问题本身.Omer想要触摸文本字段并弹出框.
此解决方案显示用户输入文本时的弹出窗口.
我在Jens Alfke的cocoabuilder上找到了这个答案.我在这里重新发布了他的代码.谢谢Jens.
原cocoabuilder帖子:(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];
}
Run Code Online (Sandbox Code Playgroud)
我在我的controlTextDidChange:方法中使用了这段代码.
- (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]; }
}
}
Run Code Online (Sandbox Code Playgroud)
true如果 NSComboBox 的列表已展开,则返回
comboBox.cell?.isAccessibilityExpanded() ?? false\nRun Code Online (Sandbox Code Playgroud)打开 NSComboBox 的列表
\n\ncomboBox.cell?.setAccessibilityExpanded(true)\nRun Code Online (Sandbox Code Playgroud)关闭 NSComboBox 的列表
\n\ncomboBox.cell?.setAccessibilityExpanded(false)\nRun Code Online (Sandbox Code Playgroud)NSComboBox 的设计初衷并不是以这种方式工作。由于用户可能想要编辑控件中的文本,因此他们需要能够单击它而不会意外弹出选项。
您需要对 NSComboBoxCell 进行子类化并更改此行为...但是您将拥有一个看起来标准的控件,但其行为却并非标准方式。如果您决定这样做,请查看NSComboBoxCell的开源版本。有趣的方法似乎是 -popUpForComboBoxCell: 和朋友。
| 归档时间: |
|
| 查看次数: |
3086 次 |
| 最近记录: |