[MacRuby-devel] [MacRuby] #154: Odd behavior with NSTableView
MacRuby
ruby-noreply at macosforge.org
Thu Nov 6 16:20:47 PST 2008
#154: Odd behavior with NSTableView
-------------------------------------+--------------------------------------
Reporter: parzival at mindspring.com | Owner: lsansonetti at apple.com
Type: defect | Status: new
Priority: minor | Milestone:
Component: MacRuby | Keywords:
-------------------------------------+--------------------------------------
I'm trying to learn some Mac programming via MacRuby & Xcode, so I built
the project in the tutorial here:
http://developer.apple.com/mac/articles/scriptingautomation/cocoaappswithmacruby.html
(It's a good tutorial; perhaps it should be added to the examples unless
that's already been done.)
Just playing around I tried extending it by adding a 'phone number' field.
That worked fine until I attempted to do some formatting on the input.
If you're unfamiliar with the project, it builds a simpls NSTableView with
a few fields, a Controller class, and then a Friend class to store the
data (first name, last name, etc). Aside from adding a few lines to the
Controller class, I added a setter function to the Friend class.
Here's the setter function (comments stripped):
def setphone_no (p_no)
@phone_no=p_no.gsub(/[^\d]/,'')
if @phone_no.length > 10 # || p_no[0] == '+'
@phone_no = '+' << @phone_no
end
end
This mostly works, except in the following case. If a string is entered
into a field that is only digits, and longer than the limit (10), all that
gets displayed in the table is the "+". The field works okay if you
change the number after that. In fact, the number seems to be stored
okay; it's only being displayed properly that is the problem.
Adding the second test condition has no effect. However, strings which
fail the first test and pass the second are okay. It's only the ones that
are 'too long' that end up missing.
Strings that work:
The default string that gets passed from the Controller class :
"0123456789012" (but this does NOT work if typed in)
"+012345" (any string with a leading + (regardless of length if the second
condition is turned on))
"01234567890 12" (any long string with a non-numeric in it)
"0123456789" (any string of 10 or fewer digits)
Other things tried:
Using either attr_reader or a custom getter makes no difference.
I tried using a different attached marker ('INT' instead of '+') -
whatever the marker is is all that gets displayed for 'bad' strings.
No difference using ' vs. " or + vs. << to add the marker.
Changing the length limit affects the length of strings that will not get
displayed, but otherwise shows the same problem.
Changing the test condition order has no effect.
Looking at the console output using 'debugging' puts lines, the Friend
object always shows the entered value correctly (e.g. when updating the
table after another entry is changed). The class (when setting or
getting) shows up as NSMutableString.
This problem doesn't seem to show up when doing this without a GUI. I
pulled out what just the Friend class and made a simplified Controller
class, and it tested fine in macirb.
Project is attached.
--
Ticket URL: <http://www.macruby.org/trac/ticket/154>
MacRuby <http://macruby.org/>
More information about the MacRuby-devel
mailing list