如何在xcode中使用objective c和cocoa框架动态添加NSComboBox数据?
-(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
}
似乎无法获得正确的字符串,因为它最终会出现垃圾变量。