NSComboBox 使用方法

NSComboBox 使用方法

在XCode里面

功能:

1.给combobox填充值

2.选中combobox后变化

3.删除cobobox里面的值

4.指定combobox里面显示的值

m文件

#import "Your AppDelegate.h"

@implementation QXSAppDelegate

@synthesize m_combobox;

@synthesize m_LB_Show;

@synthesize  m_BT_1;

- (void)dealloc
{
    [super dealloc];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    m_LB_Show.stringValue = @"";
    [self OnBT_FullValues:m_BT_1];
    [self OnComboboxChanged:m_combobox];
    
}
- (IBAction)OnBT_FullValues:(id)sender
{
    id value1;
    NSString *value_str1;
    
    // Delete all item
    [m_combobox removeAllItems];
    
    // Add items to ComboBox
    value_str1 = @"Jan";
    value1=value_str1;
    [m_combobox addItemWithObjectValue:(value1)];
    [m_combobox addItemWithObjectValue:(@"Fre")];
    [m_combobox addItemWithObjectValue:(@"March")];
     [m_combobox addItemWithObjectValue:(@"April")];
     [m_combobox addItemWithObjectValue:(@"May")];
     [m_combobox addItemWithObjectValue:(@"June")];
     [m_combobox addItemWithObjectValue:(@"July")];
     [m_combobox addItemWithObjectValue:(@"August")];
     [m_combobox addItemWithObjectValue:(@"September")];
     [m_combobox addItemWithObjectValue:(@"Octorber")];
    
    // Set show Item
    [m_combobox selectItemAtIndex:0];
}

- (IBAction)OnBT_FullValues1:(id)sender
{
    id value1;
    NSString *value_str1;
    
    // Delete all item
    [m_combobox removeAllItems];
    
    // Add items to ComboBox
    value_str1 = @"Monday";
    value1=value_str1;
    [m_combobox addItemWithObjectValue:(value1)];
    [m_combobox addItemWithObjectValue:(@"Tuesday")];
    [m_combobox addItemWithObjectValue:(@"Wednesday")];
    [m_combobox addItemWithObjectValue:(@"Thurday")];
    [m_combobox addItemWithObjectValue:(@"Friday")];
    [m_combobox addItemWithObjectValue:(@"Saturday")];
    [m_combobox addItemWithObjectValue:(@"Sunday")];
    
    // Set show Item
    [m_combobox selectItemAtIndex:0];
}

- (IBAction)OnBTAnother:(id)sender
{
    NSInteger int_count = 0;
    [m_combobox addItemWithObjectValue:(@"1")];
    [m_combobox addItemWithObjectValue:(@"2")];
    [m_combobox addItemWithObjectValue:(@"3")];
    [m_combobox addItemWithObjectValue:(@"4")];
    [m_combobox addItemWithObjectValue:(@"5")];
    [m_combobox addItemWithObjectValue:(@"6")];
}

- (IBAction)OnBTClear:(id)sender
{
    // Delete all item
    [m_combobox removeAllItems];
    m_combobox.stringValue = @"";
}

- (IBAction)OnComboboxChanged:(id)sender
{
    NSInteger index_for_combox = [m_combobox indexOfSelectedItem];
    NSString *m_text_combobox;
    m_text_combobox = [m_combobox itemObjectValueAtIndex:index_for_combox];
    
    if ([m_text_combobox isEqualToString:@""]==YES)
    {
        m_LB_Show.stringValue = @"";
    }
    else
    {
        m_LB_Show.stringValue = m_text_combobox;
    }
}
@end


h文件

#import <Cocoa/Cocoa.h>

@interface QXSAppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet NSTextField *m_LB_Show;
@property (assign) IBOutlet NSButton *m_BT_1;

@property (assign) IBOutlet NSComboBox *m_combobox;
@end


完毕!

测试成功!

  • 0
    点赞
  • 1
    收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论 1

打赏作者

A_XCODE_TEACHER

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值