我有一个加载了访问的 sqlite3 数据库,并试图将下表的内容放入 NSComboBox 中(然后根据其他操作参数自动选择默认键)。以下是表格内容:
(table) _backup_increment:
('incrementid', 'value', 'description')
(1, 'h', 'hours')
(2, 'd', 'days')
(3, 'w', 'weeks')
(4, 'm', 'months')
(5, 'y', 'years')
目标是以某种方式(最好是在代码中,但如果我必须使用绑定,或者如果它被认为是更好的做法)将这些项目加载到 NSComboBox 中,如下所示:
_______________________
key: [ (Select Value) |\/]
-----------------------
key:1 | h (hours) |
key:2 | d (days) |
key:3 | w (weeks) | (* auto select this one as the default for now)
key:4 | m (months) |
key:5 | y (years) |
-----------------------
我在某个时候创建了一个 BackupIncrement 类,其中包含 3 个公开的实例变量作为 incrementid、value 和 description 的属性。并且打算尝试加载一个 NSMutableArray 并尝试以编程方式将其链接为数据源,但我似乎无法让它工作。到目前为止,这是我的代码,您可以看到我一直在使用对象和可变数组的位置:
-(void)doAddItemsTocmbDefaultBackupIncrement {
const char* chrSQLSelect = "SELECT * FROM _backup_increments";
sqlite3_stmt* compiledSQL;
if (sqlite3_prepare_v2(claAppDelegate.sl3Database, chrSQLSelect, -1, &compiledSQL, NULL) == SQLITE_OK) {
while (sqlite3_step(compiledSQL) == SQLITE_ROW) {
BackupIncrement* bi = [[BackupIncrement alloc]
initWithintIncrementId:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledSQL, 0)]
AndstrIncrementValue:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledSQL, 1)]
AndstrIncrementDescription:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledSQL, 2)]];
//[cmbDefaultBackupIncrement addItemWithObjectValue:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledSQL, 1)]];
[cmbDefaultBackupIncrement addItemWithObjectValue:bi];
[marBackupIncrement addObject:bi];
// NSLog(@"%ld: %@(%@)",
// (long)[[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledSQL, 0)] integerValue],
// [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledSQL, 1)],
// [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledSQL, 2)]);
// NSLog(@"===========");
}
for (id obj in marBackupIncrement)
NSLog(@"obj: %@", [obj valueForKey:@"intIncrementId"]);
[cmbDefaultBackupIncrement reloadData];
//NSLog(@"What? %@", marBackupIncrement);
}
}
所以是的 - 非常感谢以编程方式或 XCode5 中的绑定进行此操作的任何帮助!谢谢!