objective-c - 如何获取ComboBox的索引?

标签 objective-c cocoa

所以我有一个类“mainpercentage.m”,并且我希望该类中的一个变量假定 ComboBox 索引的值。我尝试过方法“indexOfSelectedItem”,但我无法理解语法。 感谢您的帮助!

Mainpercentage.m:

@implementation MainPercentage
- (IBAction)SetPercentage:(id)sender {
/*

Here I want get index of my ComboBox

*/
    if (1==1) {
        [pryam setIntValue:40]; //pryam- FormCell
        [razb setIntValue:30];
        [estestv setIntValue:30];
    }

}

- (IBAction)GetKon:(id)sender {

}
@end

Mainpercentage.h:
#import <Cocoa/Cocoa.h>

@interface MainPercentage : NSObject {
    IBOutlet id estestv;
    IBOutlet id pryam;
    IBOutlet id razb;
}
- (IBAction)SetPercentage:(id)sender;
@end

最佳答案

From the docs :

- (NSInteger)indexOfSelectedItem

因此,如果您有一个 NSComboBox,我们将其命名为 myCombo,您会这样说:

NSInteger indexInteger = [myCombo indexOfSelectedItem];

现在indexInteger是一个NSInteger,其值为索引。

关于objective-c - 如何获取ComboBox的索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5361315/

相关文章:

objective-c - Gmail API 用于 Objective-C?

macos - 连续 NSTextField

cocoa - 在 Mac App Store 的 Cocoa 应用程序中使用正则表达式

xcode - kCGErrorIllegalArgument : _CGSFindSharedWindow?

iphone - 将视频复制到 uipasteboard

iphone - 将顶点数组和面索引加载到 OpenGL-ES 中的最快方法?

iphone - 仅在设备上运行应用程序时出现崩溃问题

ios - 使用 Evernote Cloud SDK 2.0 从 ENNoteContent 中获取 NSString

objective-c - NSView Controller 位于 NSWindow Controller 内部吗?

ios - 如何将数字添加到 NSURL?参数错误太多