Following Craig’s tutorial - I can bind one table to an array successfully
I now have a new array that I want to bind to a second table - how do i tell one table to get its values from one place and the other table to get its values from another place?
Sorry for such a dumb question!
OLIx
Add another array controller.
Craig’s method shows using a datasource. Now I can’t see anyway of defining which things go into that data source.
There is this:
on tableView_objectValueForTableColumn_row_(aTableView, aColumn, aRow)
if theCountryArray’s |count|() is equal to 0 then return end
set ident to aColumn's identifier
set theRecord to theCountryArray's objectAtIndex_(aRow)
set theValue to theRecord's objectForKey_(ident)
return theValue
end tableView_objectValueForTableColumn_row_
on numberOfRowsInTableView_(aTableView)
try
if theCountryArray's |count|() is equal to null then
else
return theCountryArray's |count|()
end if
on error
return 0
end try
end numberOfRowsInTableView_
which are the proscribed methods for this type of access - but I don’t see how i can then make a new version of this to apply to a new array…
Arghhh
You can either do it with another class as datasource, or have your handlers check which table is involved by checking aTableView, and responding appropriately. IMO a second table is all the more reason to use array controllers and bindings rather than datasources.
I’m up for trying array controllers…
but i’ve not set one up - can you give me a heads up on where to look and the form of script needed to do this!
Cheers
OLIx
ps - seems like i owe you a beer now!
Hve a look at this: http://www.scriptingmatters.com/ASObjC. I’d probably do it a bit different now – using a separate class instead of records for every row – but it gives an idea of the bindings and how the array controller fits in.
I seem to have solved it with an if statement in the two required methods i posted which works a charm!
Feel like I’m getting somewhere…
on tableView_objectValueForTableColumn_row_(tv, aColumn, aRow)
if tv = aTableView then
if theCountryArray's |count|() is equal to 0 then return end
set ident to aColumn's identifier
set theRecord to theCountryArray's objectAtIndex_(aRow)
set theValue to theRecord's objectForKey_(ident)
return theValue
else if tv = bTableView then
if scoreboardArray's |count|() is equal to 0 then return end
set ident to aColumn's identifier
set theRecord to scoreboardArray's objectAtIndex_(aRow)
set theValue to theRecord's objectForKey_(ident)
return theValue
end if
end tableView_objectValueForTableColumn_row_