NSComboBox 使用方法

来源:互联网 发布:试玩软件赚钱 编辑:程序博客网 时间:2024/05/21 13:17

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 0
原创粉丝点击