Table View Application

Hi Shane,

Thanks again for the reply.

That’s an interesting idea I’ll have to play with that to find out how a new entry would be created.

I’m still trying to figure this sort thing out.

Is there a way to do the following without the user having to click on the column header?

set sortDesc to myTableView's sortDescriptors()
theData's sortUsingDescriptors_(sortDesc)
myTableView's reloadData()

Thanks,
CQ

New issue: If I sort the table by clicking the table column header and use the code below the selectedRow index doesn’t match up with the what’s in theData.


set my itemOne to itemOne of item ((myTableView's selectedRow as integer)+1) of theData

That’s right. The raw data and what’s showing in the table don’t match in order. Get the data directly from the array controller (selectedObjects()).

Clicking on a column header sets the array controller’s sortDescriptors property. Until you do that, the controller has no sortDescriptors – unless you add them using setSortDescriptors_, passing an array of NSSortDescriptors.

Shane,

Thanks! I’ll give that a try.

Also, your book is great! It has been so helpful!

CQ

What am I doing wrong?


set theDescriptor to SortDescriptorClass's sortDescriptorWithKey_ascending_("jobDate",true)
log theDescriptor -- (jobDate, ascending, compare:)
theArrayController's sortUsingDescriptors_({theDescriptor})

I get this error:
unrecognized selector sent to instance

I was using sortUsingDescriptors_ instead of setSortDescriptors_

It’s working now. Thanks

Now I’m having an issue trying to update a value of one of the array controller objects by key.


set theArrayController's arrangedObjects()'s objectAtIndex_(0)'s valueForKey_("itemOne") to "A new Value"

I get this error:
Can’t set «class ocid» id «data kptr00000000E098017CFF7F0000» to “A new Value”

I dug through your book and found this and it seems to be working


theArrayController's arrangedObjects()'s objectAtIndex_(0)'s setValue_forKey_({{"A new Value"}},"itemOne")

You don’t need the {{ and }} around the value. But yes, you will find a lot of methods that begin with set, and it’s hard getting out of the AS habit of trying to use the set command.

New issue…

If I connect a date picker object to this function:


on dateChange_(sender)
    log "Change"   
end dateChange_

I Notice it logs “Change” twice. One on mouse down and one on up. How do you detect event type? So the function only executes on one or the other.

actually it appears that it triggers on mouse click and then again if the date was actually changed

any way to listen for a specific event type?

Not without subclassing it. You can always check its before and after value.

Shane,

Thanks I’ll try that.

I’m also trying to implement your helper classes “ObjectWithFords” and I followed these directions:

No matter which helper I try to use I get this error:

I figured it out. I was adding by dragging and not “Add to project”