Re: Displaying NSPopUpButtonCells in NSTableView
On May 20, 2010, at 3:28 PM, James Maxwell wrote: > hmm... Well, I've tried returning the cell's selectedItem, > indexOfSelectedItem, and also: > > [[inst MIDI_Inst_Ports] objectAtIndex:[ports indexOfSelectedItem]] > > (that is, the port name at indexOfSelectedItem). > If I NSLog the [ports indexOfSelectedItem] it's always zero. So I'm obviously > not understanding how (or when) the cell gets selected. > > Maybe the menu/cell selection is a separate process? Do I need to control the > popup separately? > I'll look into NSPopUpButtonCell again, but if anyone see's what I'm missing, > please pop me a note. The first thing to always remember is that the designer of NSTableView was an unabashed sadist. Now that that is out of the way What NSTableView needs from you is to tell it what the selected index *should* be, so *it* can set the selected item in the popupbutton. I.e., the tableview wants to control the popupbutton. All you should do is touch it during delegate calls. I believe if you return nil, the first item will be selected. If every cell's popup will have the same content (albeit varying selections), your sanity will remain intact. Otherwise, I shudder to think > On 2010-05-20, at 2:04 PM, James Maxwell wrote: > >> On 2010-05-20, at 1:28 PM, Peter Ammon wrote: >> >>> >>> On May 20, 2010, at 1:14 PM, James Maxwell wrote: >>> I thought I'd change the topic on this, since the content really has changed. I have an table for setting up MIDI instruments with a name, port, and channel. I've got the initial display of options for the table row displaying correctly, and when I make changes to the name, port, and channel, the data object is updated correctly. The only thing left is that the popups in columns 2 and 3 are not holding the selected value. I understand that this is probably because I'm reloading the menu in tableView:objectValueForTableColumn:row, but I'm not sure how to get around it. Here's the code I've got so far. I'm not using an NSArrayController, because that approach was driving me absolutely mental... I've copied all the code (except imports) to be thorough. Logging "Edited MIDIInstrument" at the end shows that the instrument is set up correctly, with the desire name, port, and channel. It's just that the popups always display the 2nd item. Keary Suska Esoteritech, Inc. "Demystifying technology for your home or business" ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Displaying NSPopUpButtonCells in NSTableView
hmm... Well, I've tried returning the cell's selectedItem, indexOfSelectedItem, and also: [[inst MIDI_Inst_Ports] objectAtIndex:[ports indexOfSelectedItem]] (that is, the port name at indexOfSelectedItem). If I NSLog the [ports indexOfSelectedItem] it's always zero. So I'm obviously not understanding how (or when) the cell gets selected. Maybe the menu/cell selection is a separate process? Do I need to control the popup separately? I'll look into NSPopUpButtonCell again, but if anyone see's what I'm missing, please pop me a note. thanks, J. On 2010-05-20, at 2:04 PM, James Maxwell wrote: > ah, that makes sense. I'll make the change and see if that fixes it. > > thanks, Peter. > > J. > > > On 2010-05-20, at 1:28 PM, Peter Ammon wrote: > >> >> On May 20, 2010, at 1:14 PM, James Maxwell wrote: >> >>> I thought I'd change the topic on this, since the content really has >>> changed. >>> >>> I have an table for setting up MIDI instruments with a name, port, and >>> channel. I've got the initial display of options for the table row >>> displaying correctly, and when I make changes to the name, port, and >>> channel, the data object is updated correctly. The only thing left is that >>> the popups in columns 2 and 3 are not holding the selected value. I >>> understand that this is probably because I'm reloading the menu in >>> tableView:objectValueForTableColumn:row, but I'm not sure how to get around >>> it. >>> >>> Here's the code I've got so far. I'm not using an NSArrayController, >>> because that approach was driving me absolutely mental... >>> I've copied all the code (except imports) to be thorough. Logging "Edited >>> MIDIInstrument" at the end shows that the instrument is set up correctly, >>> with the desire name, port, and channel. It's just that the popups always >>> display the 2nd item. >> >> Hi James, >> >> If you have a table view containing an NSPopUpButtonCell, the object value >> returned by your objectValueForTableColumn: method should be an NSNumber, >> which contains the index of the item that should be selected. It looks like >> the attached code is returning the cell itself, which is strange, and I >> think that's causing the problem. >> >> Hope this helps, >> -Peter >> > > James B Maxwell > Composer/Doctoral Student > School for the Contemporary Arts (SCA) > School for Interactive Arts + Technology (SIAT) > Simon Fraser University > jbmaxw...@rubato-music.com > jbmax...@sfu.ca > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/cocoa-dev/jbmaxwell%40rubato-music.com > > This email sent to jbmaxw...@rubato-music.com James B Maxwell Composer/Doctoral Student School for the Contemporary Arts (SCA) School for Interactive Arts + Technology (SIAT) Simon Fraser University jbmaxw...@rubato-music.com jbmax...@sfu.ca ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Displaying NSPopUpButtonCells in NSTableView
ah, that makes sense. I'll make the change and see if that fixes it. thanks, Peter. J. On 2010-05-20, at 1:28 PM, Peter Ammon wrote: > > On May 20, 2010, at 1:14 PM, James Maxwell wrote: > >> I thought I'd change the topic on this, since the content really has changed. >> >> I have an table for setting up MIDI instruments with a name, port, and >> channel. I've got the initial display of options for the table row >> displaying correctly, and when I make changes to the name, port, and >> channel, the data object is updated correctly. The only thing left is that >> the popups in columns 2 and 3 are not holding the selected value. I >> understand that this is probably because I'm reloading the menu in >> tableView:objectValueForTableColumn:row, but I'm not sure how to get around >> it. >> >> Here's the code I've got so far. I'm not using an NSArrayController, because >> that approach was driving me absolutely mental... >> I've copied all the code (except imports) to be thorough. Logging "Edited >> MIDIInstrument" at the end shows that the instrument is set up correctly, >> with the desire name, port, and channel. It's just that the popups always >> display the 2nd item. > > Hi James, > > If you have a table view containing an NSPopUpButtonCell, the object value > returned by your objectValueForTableColumn: method should be an NSNumber, > which contains the index of the item that should be selected. It looks like > the attached code is returning the cell itself, which is strange, and I think > that's causing the problem. > > Hope this helps, > -Peter > James B Maxwell Composer/Doctoral Student School for the Contemporary Arts (SCA) School for Interactive Arts + Technology (SIAT) Simon Fraser University jbmaxw...@rubato-music.com jbmax...@sfu.ca ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Displaying NSPopUpButtonCells in NSTableView
On May 20, 2010, at 1:14 PM, James Maxwell wrote: > I thought I'd change the topic on this, since the content really has changed. > > I have an table for setting up MIDI instruments with a name, port, and > channel. I've got the initial display of options for the table row displaying > correctly, and when I make changes to the name, port, and channel, the data > object is updated correctly. The only thing left is that the popups in > columns 2 and 3 are not holding the selected value. I understand that this is > probably because I'm reloading the menu in > tableView:objectValueForTableColumn:row, but I'm not sure how to get around > it. > > Here's the code I've got so far. I'm not using an NSArrayController, because > that approach was driving me absolutely mental... > I've copied all the code (except imports) to be thorough. Logging "Edited > MIDIInstrument" at the end shows that the instrument is set up correctly, > with the desire name, port, and channel. It's just that the popups always > display the 2nd item. Hi James, If you have a table view containing an NSPopUpButtonCell, the object value returned by your objectValueForTableColumn: method should be an NSNumber, which contains the index of the item that should be selected. It looks like the attached code is returning the cell itself, which is strange, and I think that's causing the problem. Hope this helps, -Peter ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Displaying NSPopUpButtonCells in NSTableView
I thought I'd change the topic on this, since the content really has changed. I have an table for setting up MIDI instruments with a name, port, and channel. I've got the initial display of options for the table row displaying correctly, and when I make changes to the name, port, and channel, the data object is updated correctly. The only thing left is that the popups in columns 2 and 3 are not holding the selected value. I understand that this is probably because I'm reloading the menu in tableView:objectValueForTableColumn:row, but I'm not sure how to get around it. Here's the code I've got so far. I'm not using an NSArrayController, because that approach was driving me absolutely mental... I've copied all the code (except imports) to be thorough. Logging "Edited MIDIInstrument" at the end shows that the instrument is set up correctly, with the desire name, port, and channel. It's just that the popups always display the 2nd item. thanks, J. @implementation MIDI_Instrument_Controller @synthesize instrumentLibrary; @synthesize selectedInstrument; - (id) init { self = [super init]; if(self) { NSMutableArray* inst = [[NSMutableArray alloc] init]; [self setInstrumentLibrary:inst]; [inst release]; } return self; } - (IBAction)addInstrumentToLibrary: (id)sender { MIDIInstrument* newInst = [[MIDIInstrument alloc] init]; [[self instrumentLibrary] addObject:newInst]; [self setSelectedInstrument:newInst]; [newInst release]; [midiInstrumentsTable reloadData]; NSIndexSet* idxs = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(([[self instrumentLibrary] count] - 1), 1)]; [midiInstrumentsTable selectRowIndexes:idxs byExtendingSelection:NO]; [midiInstrumentsTable editColumn:0 row:([[self instrumentLibrary] count] - 1) withEvent:nil select:YES]; } - (IBAction)removeInstrumentFromLibrary: (id)sender { if([self selectedInstrument] != nil) { [[self instrumentLibrary] removeObject:[self selectedInstrument]]; [midiInstrumentsTable reloadData]; } } - (void)tableViewSelectionDidChange: (NSNotification*)notification { int row = [midiInstrumentsTable selectedRow]; if(row >= 0) [self setSelectedInstrument:[[self instrumentLibrary] objectAtIndex:row]]; } - (NSInteger) numberOfRowsInTableView:(NSTableView*)tv { if(tv == midiInstrumentsTable) return [[self instrumentLibrary] count]; return 0; } - (id) tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tc row:(NSInteger)row { NSLog(@"Updating instruments table..."); if(tv == midiInstrumentsTable) { id inst = [[self instrumentLibrary] objectAtIndex:row]; if(inst == nil) return nil; if(tc == midiInstNamesColumn) { // give the name for the associated MIDIInstrument [tc setEditable:YES]; return [inst MIDI_Inst_Name]; } else if(tc == midiPortsColumn) { // list the ports for the associated MIDIInstrument [tc setEditable:YES]; NSPopUpButtonCell* ports = [tc dataCell]; [ports removeAllItems]; int i; for(i=0;i < [[inst MIDI_Inst_Ports] count];i++) [ports addItemWithTitle:[[inst MIDI_Inst_Ports] objectAtIndex:i]]; return ports; } else if(tc == midiChannelsColumn) { // list the channels for the associated MIDIInstrument (just 16 numbers) [tc setEditable:YES]; NSPopUpButtonCell* channels = [tc dataCell]; [channels removeAllItems]; int i; for(i=0;i < 16;i++) [channels addItemWithTitle:[NSString stringWithFormat:@"%i", i+1]]; return channels; } } return nil; } - (void) tableView:(NSTableView *)tv setObjectValue:(id)v forTableColumn:(NSTableColumn *)tc row:(NSInteger)row { NSLog(@"Updating instruments..."); if (tv == midiInstrumentsTable) { MIDIInstrument* inst = [[self instrumentLibrary] objectAtIndex:row]; if(inst == nil) return; if (tc == midiInstNamesColumn) { // set the given name [inst setMIDI_Inst_Name:v];