Question

I have an sqlite3 database loaded an accessed and am trying to put the contents of the following table into an NSComboBox (and then auto-select the default key bases on other operating parameters). Here is the table contents:

(table) _backup_increment:
('incrementid', 'value', 'description')
(1, 'h', 'hours')
(2, 'd', 'days')
(3, 'w', 'weeks')
(4, 'm', 'months')
(5, 'y', 'years')

The goal is to somehow (ideally in code but using bindings if I have to, or if it is considered to be a better practice) load up those items into a NSComboBox like so:

      _______________________
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)           |
      -----------------------

I at some point made a BackupIncrement class with 3 exposed instance variables as properties for incrementid, value, and description. And was going to try to load up an NSMutableArray and try to programatically link that as the datasource, but I can't seem to get it working. Here is my code so far, you can see where I have been playing with the object and the mutable array:

-(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);
    }
}

So yeah - any help with doing this programmatically or with Bindings in XCode5 would be greatly appreciated! thanks!

Was it helpful?

Solution

I discovered that my issue was ultimately one of timing. I ended up switching to an NSPopupButton, but here is where I ended up: programatically adding menu items to nspopupbutton

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top