From: Steven D.A. <st...@ne...> - 2005-12-09 06:55:12
|
I am using rubycocoa version 0.4.2 and ruby 1.8.4 in a dictionary application I'm writing. As part of the dictionary, each word has a number of synonyms with which it may be associated; these are presented in an NSTableView. I have a button that allows a user to add a row to the table, where they can then type in the word. Since I have several tables like this, instead of implementing each one separately, since the logic is very similar, I have defined a generic function for adding a row to a table; supply the attribute name as a string and we get the attribute and then apply the logic to add the new row. The code looks like this: 01 def addGeneric(sender, attribute) 02 # Edit a single-column tableview. 03 attribute = self.instance_variable_get("@#{attribute}") 04 num_rows = attribute.numberOfRows - 1 05 idx_set = NSIndexSet.indexSetWithIndex(num_rows) 06 attribute.selectRowIndexes_byExtendingSelection(idx_set, true) 07 attribute.editColumn_row_withEvent_select(0, num_rows, nil, true) 08 end This code selects the last row in the tableview. For example, if there are three rows containing values "moe", "curly" and "larry", respectively, then "larry" would be selected. If you typed something, "larry" would be overwritten. This isn't quite what I want. I want the _next_ row to become editable, allowing the user to then type in a new value that wasn't previously in the list. Given this, I assume that it will work if I just remove the "-1" on line 4. But when I test this, when I click the add button, I get this error: 2005-12-09 01:44:38.390 rubydict[7485] *** Assertion failure in - [NSTableView editColumn:row:withEvent:select:], TableView.subproj/ NSTableView.m:3855 /Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/ objc/oc_wrapper.rb:17:in `NSApplicationMain': NSApplicationMain - NSInternalInconsistencyException - Invalid parameter not satisfying: _lastSelectedRow == row (OSX::OCException) from /Volumes/secure_fw/Documents/Personal/Development/ new_dictionary/rubydict/build/Development/rubydict.app/Contents/ Resources/rb_main.rb:23 Any idea what might be going on here? BTW, very similar logic works in Python using PyObjC. Thanks in advance, steve |
From: Jonathan P. <jp...@dc...> - 2005-12-09 10:20:32
|
On 9 Dec 2005, at 6:55, Steven D.Arnold wrote: > Any idea what might be going on here? BTW, very similar logic > works in Python using PyObjC. I don't see anywhere in your code where you add a new row to the NSTableView. The error you're seeing occurs because the row being asked for doesn't exist. Is your NSTableView populated using a datasource or bindings? With a datasource, I think you may have to add a prototype element to the datasource and call tableView.reloadData. After that, you can hopefully select the new row. With bindings, you add a new row by going through the NSTableView's NSArrayController (you can bind insert: directly to a button's action). Can you give an example of the PyObjC code that works? Cheers, Jonathan |
From: Neil S. <ne...@ha...> - 2005-12-09 12:21:48
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Steven D.Arnold wrote: > I want > the _next_ row to become editable, allowing the user to then type in a > new value that wasn't previously in the list. I do something like this: def addClicked # @data is the array used in my table view data source methods @data << 'URL' # @view is the view, now that we added a row, we notify it # that we did @view.noteNumberOfRowsChanged # NOW I select the last row, and begin editing it, # because I know it is the new row. row = @urls.size - 1 indexSet = OSX::NSIndexSet.indexSetWithIndex(row) @view.selectRowIndexes_byExtendingSelection(indexSet, false) @view.editColumn_row_withEvent_select(0, row, nil, true) end - -- Neil Stevens - ne...@ha... 'A republic, if you can keep it.' -- Benjamin Franklin -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Darwin) iD8DBQFDmXbVf7mnligQOmERAmL9AKCad6R40RiO0rfEBRXeD45i3qLcygCbBhrk mIGs+8H6d1ARswvmO1Qho24= =uwoj -----END PGP SIGNATURE----- |
From: Neil S. <ne...@ha...> - 2005-12-09 12:23:41
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Neil Stevens wrote: > def addClicked > # @data is the array used in my table view data source methods > @data << 'URL' > # @view is the view, now that we added a row, we notify it > # that we did > @view.noteNumberOfRowsChanged > > # NOW I select the last row, and begin editing it, > # because I know it is the new row. > row = @urls.size - 1 Sorry, that should read @data.size - 1, I missed one rename when I simplified the variable names for the example. > indexSet = OSX::NSIndexSet.indexSetWithIndex(row) > @view.selectRowIndexes_byExtendingSelection(indexSet, false) > @view.editColumn_row_withEvent_select(0, row, nil, true) > end - -- Neil Stevens - ne...@ha... 'A republic, if you can keep it.' -- Benjamin Franklin -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Darwin) iD8DBQFDmXdIf7mnligQOmERAjIuAJ9BZJeWwX4i5nDUYQLfF9N9Tqw73gCgko2t zrV9poJWzZKS1sGn4wDIeSc= =7ava -----END PGP SIGNATURE----- |
From: Jonathan P. <jp...@dc...> - 2005-12-09 12:29:45
|
On 9 Dec 2005, at 12:23, Neil Stevens wrote: >> def addClicked >> # @data is the array used in my table view data source methods >> @data << 'URL' >> # @view is the view, now that we added a row, we notify it >> # that we did >> @view.noteNumberOfRowsChanged Does this mean the problem is now resolved? Cheers, Jonathan |