Greetings I have the following problem trying to set a datasource in an NSComboBox
.
This is my custom datasource class:
@interface CComboDatasource : NSObject <NSComboBoxDataSource> {
@private
NSMutableArray* values;
}
@property (nonatomic,retain) NSMutableArray* values;
-(int)itemCount;
@end
@implementation CComboDatasource
@synthesize values;
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
values=[[NSMutableArray alloc] init];
[values addObject:@"A"];
[values addObject:@"B"];
[values addObject:@"C"];
}
return self;
}
- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
{
return [values count];
}
- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index
{
return [values objectAtIndex:index];
}
- (void)dealloc
{
[values release];
[super dealloc];
}
@end
Later in another file I connect my IBOutlet
with my NSComboBox
object (c_box) and I set the datasource (CComboDatasource* data_source)
.
[c_box setUsesDataSource:TRUE];
[c_box setDataSource:data_source];
[c_box setEditable:NO];
After the previous actions nothing is displayed in the combo box, what am I doing wrong?