How to dynamically add NSComboBox data using objective c and cocoa framework in xcode?
-(void)awakeFromNib
{
NSLog(@"View controller instance with view: %@", self.view);
char* data = getData(); // I will be using data to populate records below
// Setup combo box with data from getData() instead of dummy apple, bag, cat, dog
self.myRecords = @[@“apple”, @“bag”, @“cat”, @“dog"];
[self.myRecordsCombo addItemsWithObjectValues:self.myRecords];
}
// C Method
int
getData()
{
char name[128];
NSString *str;
while(/*traverse through data for combo box */){
NSString *tempName = [NSString stringWithFormat:@"%c", name];
str = [str stringByAppendingString:tempName];
....
}
NSLog(str); //will be passed to awakeFromNib and populate to combo box
}
Can't seem to get the right strings as it will end up with garbage variables.
First you need to create the list of items. (NSArray).
Remove all existing items as by default three items gets added to combo box.
Now add your items to the combo box: