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 |