Re: Get controller from nib
Re: Get controller from nib
- Subject: Re: Get controller from nib
- From: Reinhard Segeler <email@hidden>
- Date: Thu, 27 May 2010 11:47:28 +0200
Hi James,
today I read your mail:
I ran into a problem with the reference some time ago. I have solved
it by posting/observing a notification with the reference as the only
object in the userInfo dict.. That works fine and assures, that the
reference can be determined exactly. The only problem can be, to send
it at the correct time, but that's solvable.
Your problem with the tableView/array controller: I strongly recommend
to read the book of Aaraon Hillegass Programming MacOS X, where the
handling of tableView/array controllers etc. is fairly good
explained!!! I could send you a project, that I created from the book,
but it's only helpful, if you have a certain unterstanding of the
basics.
-- Reinhard
Am 20.05.2010 um 19:32 schrieb James Maxwell:
So, I decided to get rid of the NSArrayController, since it was
driving me slightly crazy, and just do this manually. I've got the
table **appearing** as I'd like it to, but I can't change the
selection. There are 3 columns: 1) string, 2) NSPopUpButtonCell for
MIDI ports, and 3) NSPopUpButtonCell for MIDI channels. Basically,
nothing can be changed. It comes up as 1) "default" (set in the init
of MIDIInstrument), 2) as item 2 in column 2's popup, and 3) as item
2 in column 3's popup.
I don't know if maybe I have the functions of these two methods
reversed somehow, or what. The naming of the methods is a bit
unclear. I'm assuming that "objectValueForTableColumn" would mean
what I want to "give" to the table for display, whereas
"setObjectValue:forTableColumn" would be what I want to "give" to my
object, from the table. Mind you, the latter would be clearer as
"setObjectValue:fromTableColumn", if that was the case... dunno...
Here's my manual code for updating the table:
- (id) tableView:(NSTableView *)tv objectValueForTableColumn:
(NSTableColumn *)tc row:(NSInteger)row
{
if(tv == midiInstrumentsTable)
{
id inst = [[self instrumentLibrary] objectAtIndex:row];
if(inst == nil)
return nil;
if(tc == midiInstNamesColumn)
{
// give the name for the associated MIDIInstrument
return [inst MIDI_Inst_Name];
}
else if(tc == midiPortsColumn)
{
// list the ports for the associated MIDIInstrument
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)
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
{
if (tv == midiInstrumentsTable)
{
id inst = [[self instrumentLibrary] objectAtIndex:row];
if(inst == nil)
return;
if (tc == midiInstNamesColumn)
{
// set the given name
[inst setMIDI_Inst_Name:[[tc dataCell] title]];
}
else if(tc == midiPortsColumn)
{
// set the selected port
[inst setMIDI_Inst_Port:[[[tc dataCell] selectedItem] title]];
}
else if(tc == midiChannelsColumn)
{
// set the selected channel
[inst setMIDI_Inst_Channel:[NSNumber numberWithInt:[[[[tc
dataCell] selectedItem] title] integerValue]]];
}
}
}
Any help very much appreciated.
J.
On 2010-05-19, at 2:19 PM, James Maxwell wrote:
okay, going slightly nuts. I've implemented my
MIDI_Instrument_Controller object, and hooked it up to my table
view, but it's complaining about implementing
numberOrRowsInTableView and
tableView:objectValueForTableColumn:row:. Fine, except that I very
definitely have implemented them. I tried cleaning, and reloading
classes in IB, to no avail. Has anyone seen this? Any solutions?
J.
On 2010-05-18, at 6:27 PM, Mark Ritchie wrote:
Hey James!
On 18/May/2010, at 5:42 PM, James Maxwell wrote:
Okay, getting a bit deeper into this, I realize I'm still "in the
woods", so to speak. I'm going to have to hook up my NSTableView
to set the *selected* port and channel for the MIDIInstruments,
which means it's pretty much going to have to be loaded in the
nib after all (since the MIDIInstrument has to respond to the
selection made in the table). So, if I do that, and make the
connections to Central_MIDI_Controller, as recommended, will the
NSArrayController be able to add new instances of MIDIInstrument
(and new rows to my table), which also have these connections? As
I mentioned, I need an arbitrary number of MIDIInstruments.
It seems to me that you are not separating the model, view and
controller bits.
To me, MIDIInstrument sounds like it's part of the Model (the
internal state of things) and it should not be talking directly to
the TableView. The controller in the middle should be tracking
and co-ordinating things.
I hope that helps!
M.
James B Maxwell
Composer/Doctoral Student
School for the Contemporary Arts (SCA)
School for Interactive Arts + Technology (SIAT)
Simon Fraser University
email@hidden
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
James B Maxwell
Composer/Doctoral Student
School for the Contemporary Arts (SCA)
School for Interactive Arts + Technology (SIAT)
Simon Fraser University
email@hidden
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden