You emailed me the other day off-list about this. I replied off-list,
but I am guessing you did not get my email (I was on-the-move at the
time so maybe my email was not sent properly or maybe it has got
caught in your spam filter). Anyway, I am back in the office now and
as you have asked again on the list ...
Rainer is exactly right when he says "the 'it' referes to the table
view that is the addressee of the tell block".
You quote this from the documentation:
- (void)scrollRowToVisible:(int)rowIndex
To spell out what this means ...
"scrollRowToVisible:" is the method (think of a method as something
like an action)
the minus sign at the beginning, "-", tells us that it is an object
method as opposed to a class method. In our case it is a method that
our table view object understands. In other words, one can say to a
table view "scrollRowToVisible:" and it will know what to do (it will
scroll itself until the row we want is visible).
"(void)" means that this method does not return anything.
"(int)rowIndex" means that this method takes one argument, the index
of the row we want to scroll to, and that row index must be an
integer. In other words, when we call the method we need to pass to it
the index of the row we want to scroll to as an integer. When we call
the method from Applescript we pass the row index as the parameter to
the call method.
Below is a copy of the email I sent to you the other day. In summary I
am sure the only thing that you are missing is addressing the table
view in a tell block or, as I explain, if you prefer you can include
the reference to the table view in the call method line, "call
method ... of object table view ...". Either way, it is that you have
to associate the method "scrollRowToVisible:" with the object, the
table view, for this to work. My reply attempts to tease out what the
syntax of this call method means in plain-ish English.
Don't give up on this. You are nearly there. It is not magic. It is
simply slightly strange syntax to us applescripters!
Philip
============================================
Hi Joshua
"object it" is not a typo. It is correct.
If you look at my code, you'll see that the line
call method "scrollRowToVisible:" of object it with parameter
theIndex -- zero-based
is inside a Tell block
tell tableView
call method "scrollRowToVisible:" of object it with parameter
theIndex -- zero-based
...
end tell
So the "it" in "object it" refers to tableView (the variable
referencing the table view object).
Your equivalent lines aren't working because you have missed out the
tell block. You need this:
tell table view 1 of scroll view 1 of window MyTableView
call method "scrollRowToVisible:" of object it with parameter
theIndex -- zero-based
set selected row to (theIndex + 1)
end tell
You could write the lines without putting them in a tell block. So,
without the tell block, my lines would be:
call method "scrollRowToVisible:" of object tableView with
parameter theIndex -- zero-based
set selected row of tableView to (theIndex + 1)
and your lines would be:
call method "scrollRowToVisible:" of object (table view 1 of
scroll view 1 of window MyTableView) with parameter theIndex -- zero-
based
set selected row of (table view 1 of scroll view 1 of window
MyTableView) to (theIndex + 1)
Both ways of writing the lines work, it's just a matter of which style
you prefer.
The "call method" syntax is a little difficult to get used to. In
Cocoa objects have methods. Methods are like functions or actions that
you ask an object to perform. Objects will have an associated set of
methods - things they know how to do. So, in our example, the table
view is an object, and table view objects have the method
"scrollRowToVisible:". In other words, they know how to scroll
themselves to make visible a particular row. In Applescript Studio we
have the "call method" syntax to call a method, in other words to
instruct an object to perform a given method. So typically there are
three key elements you need to include in a call method: 1. the object
which you would like to do something, 2: the method you want the
object to perform, 3. any parameters you need to pass to the object to
enable it to perform its method. So in our example, the object is the
table view, the method is "scrollRowToVisible:" and the parameter is
theIndex - the index of the row we want the table view to scroll to.
The call method broken down is:
call method [the method] of object [the object] with parameter
[the parameter]
call method ["scrollRowToVisible:"] of object [tableView] with
parameter [theIndex]
call method "scrollRowToVisible:" of object tableView with
parameter theIndex
The other call method, "indexOfObject:", can be broken down in the
same way. In the Cocoa way of talking about things lists are arrays.
And arrays have a method "indexOfObject:". In other words, you can say
to an array (a list) "tell me what index (or position) this particular
object has within yourself", and it will return the index (position in
the list).
call method [the method] of object [the object] with parameter
[the parameter]
call method ["indexOfObject:"] of object [columnContents] with
parameter [searchItem]
call method "indexOfObject:" of object columnContents with
parameter searchItem
Sometimes you need to pass more than one parameter to a method, in
which case you pass the parameters as a list ... "with parameters {x,
y, z]" instead of "with parameter ...". There are also class methods
which have a slightly different syntax (you say "call method [the
method] of class [the class] ..."), but much the most common methods
are object methods.
Hope that helps
Philip
On Thu 1/05/08 4:19 AM , Joshua Whalen email@hidden sent:
I'm assuming this isn't the addam's family's cousin.
First, thanks so much for the help. It mostly works, and I'm
betting
the hang-up is a typo.
to refresh your memory, I needed to search a table view object for
some data. You generously responded:
<>
> set theList to {"zero", "one", "two", "three", "four", "five",
> "six", "seven", "eight", "nine", "ten"}
> set searchItem to "eight"
> tell application "TableView"
> set tableView to table view 1 of scroll view 1 of window 1
> append tableView with theList
> set columnContents to get content of data cell 1 of every data
> row of data source of tableView
> if columnContents contains searchItem then
> set theIndex to call method "indexOfObject:" of object
> columnContents with parameter searchItem -- zero-based
> tell tableView
> call method "scrollRowToVisible:" of object it with
> parameter theIndex -- zero-based
> set selected row to (theIndex + 1)
> end tell
> end if
> end tell
>
I modified this to suit my app as follows:
on SearchMe(theitem, thetable)
log theitem & " this is the search item in searchme" & return &
return
set MyTableView to thetable
--log data source id of thetable & " My table view's value" &
return
& return
if MyTableView = "main" then
set thecellvalue to 2
set theDataSource to data source of table view 1 of scroll view 1
of window "main"
log "Schedule is the window that was called" & return & return
else
if MyTableView = "chooseplaylist" then
set thecellvalue to 1
set theDataSource to data source of table view 1 of scroll view 1
of window "chooseplaylist"
end if
end if
set searchcelldata to zap_the_crap("data cell " & thecellvalue & "
of every data row of table view 1 of scroll view 1 of window " &
MyTableView)
set columnContents to get contents of data cell thecellvalue of
every data row of data source of table view 1 of scroll view 1 of
window MyTableView --as list
if columnContents contains theitem then
set theIndex to call method "indexOfObject:" of object
columnContents with parameter theitem -- zero-based
log theIndex & " here's theindex!" & return & return
--set int to theIndex as integer
call method "scrollRowToVisible:" of object int with parameter
theIndex -- zero-based
log int & " this is IT" & return & return
set selected row to (theIndex + 1)
end if
where theitem is the item to search for (a string) and thetable is
the applescript name of the window (there are two different windows
that could be sendign the search data, a different column is
searched
for each), and zap_the_crap is a sub_routine for stripping gremlins
from concatenated strings. I've attached it at the end of the
letter.
I've assumed that "object it" as in
call method "scrollRowToVisible:" of object it with parameter
theIndex -- zero-based
is a typo, and should be
call method "scrollRowToVisible:" of object int with parameter
theIndex -- zero-based
with int assumed to be integer.
however, i get the result "int is not defined" which makes perfect
sense, since I never did define it.
My run log returns:
2008-04-30 23:13:42.633 RadioKnife 1.0[924] "Clash this is the
search
field content
"
2008-04-30 23:13:42.661 RadioKnife 1.0[924] "Clash this is the
search
item in searchme
"
2008-04-30 23:13:42.696 RadioKnife 1.0[924] "Schedule is the window
that was called
You've certainly spent enough time helping me already, but if you
could shed some light on how to define int, I'd be grateful.
finally, I should mention I'm still using xcode 2.4.1. Can't
upgrade
till I finish this.
Thanks!
here's the ever-so-useful "zap_the_crap" routine some other kind
soul
on the ASS mailing list gave me last year, with freedom to share.
on zap_the_crap(in_string) -- bug fix for a string concatenation
error in applescript 2.1.1 and later that inserts bogus characters
between the concatenated elements
repeat with gremlin from 1 to 31
set in_string to replace_chars(in_string, ASCII character
(gremlin), "")
end repeat
return in_string
end zap_the_crap
Joshua
On 5 May 2008, at 20:35, Joshua Whalen wrote:
Rainer, thanks for the assist, but I don't think that's... IT. :-)
Here's the entry in the xcode docs:
scrollRowToVisible:
Scrolls the receiver vertically in an enclosing NSClipView so the
row specified by rowIndex is visible.
- (void)scrollRowToVisible:(int)rowIndex
What I don't get is what sets the value of int, and what value
should it be set to? I've tried just passing it the row index
(although the method I used may have been flawed) and still got an
error message. This was a few days ago, and I suppose I should have
noted the way I did it and the result, but it was something like this:
set int to theindex
and the error was something like "index 6 not understood" or
something to that effect.
*sigh*
Right about now, I wish I had just forced my way through the cocoa
docs instead of starting with what was already familiar as my entry
point into the wonderful world of xcode. Not bashing ASS, here, but
rather my poor understanding of cocoa.
Thanks again, Rainer, I do appreciate the effort! I'll see if
setting it back to IT does anything, but I'm pretty sure it's int.
Anyone else got a clue?
Joshua
On May 5, 2008, at 3:05 PM, Rainer Standke wrote:
To my relatively un-trained eye, the 'it' refers to the table view
that is the addressee of the tell block. And while I don't entirely
get what's going on either, that would make sense to me.
Hope this helps,
Rainer
On May 4, 2008, at 13:20 , Joshua Whalen wrote:
I recently posted a help request on this topic and got excellent
advice from <cleardot.gif><cleardot.gif>email@hidden:
There is a call method for scrolling to a particular row in a
table view: "scrollRowToVisible:". That is probably the key thing
you are missing. You pass the call method a row number (the row
you want to scroll to if that row is not already visible). You
just need to remember that this is zero-based, so 0 is the first
row, 1 the second etc.
There is also a call method, "indexOfObject:", (again, zero-
based) for getting the index of something in a list (array), so I
might well combine the two call methods. I would also select the
row as well as scrolling to it with "set selected row ...".
Getting the column contents to search on ... even if you haven't
explicitly set up an off-screen database, you can address the
data as if you had. Here is some sample code to show one way in
which it could all go together ...
set theList to {"zero", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "ten"}
set searchItem to "eight"
tell application "TableView"
set tableView to table view 1 of scroll view 1 of window 1
append tableView with theList
set columnContents to get content of data cell 1 of every data
row of data source of tableView
if columnContents contains searchItem then
set theIndex to call method "indexOfObject:" of object
columnContents with parameter searchItem -- zero-based
tell tableView
call method "scrollRowToVisible:" of object it with
parameter theIndex -- zero-based
set selected row to (theIndex + 1)
end tell
end if
end tell
Philip
The example is excellent, although I'm guessing it contains a
type, as follows:
call method "scrollRowToVisible:" of object it with
parameter theIndex -- zero-based
I'm guessing the object "IT" is actually object "INT". Reasonable
guess, I'd say.
I adapted the suggestion to my project as below:
on SearchMe(theitem, thetable)
log theitem & " this is the search item in searchme" & return &
return
set MyTableView to thetable
if MyTableView = "main" then
set thecellvalue to 2
set theDataSource to data source of table view 1 of scroll view
1 of window "main"
log "Schedule is the window that was called" & return & return
else
if MyTableView = "chooseplaylist" then
set thecellvalue to 1
set theDataSource to data source of table view 1 of scroll view
1 of window "chooseplaylist"
end if
end if
set searchcelldata to zap_the_crap("data cell " & thecellvalue &
" of every data row of table view 1 of scroll view 1 of window " &
MyTableView)
set columnContents to get contents of data cell thecellvalue of
every data row of data source of table view 1 of scroll view 1 of
window MyTableView --as list
if columnContents contains theitem then
set theIndex to call method "indexOfObject:" of object
columnContents with parameter theitem -- zero-based
log theIndex & " here's theindex!" & return & return
call method "scrollRowToVisible:" of object int with parameter
theIndex -- zero-based
log int & " this is INT" & return & return
set selected row to (theIndex + 1)
end if
end SearchMe
This works very nicely, for the most part. The logs show the
correct data being passed along the routine, etc..
The only problem is that actually running this returns this error:
"The variable int is not defined. (-2753)"
Now, my objective-c is not all it should be. I'm working on it,
honestly, but it's not all there yet.
Anyone want to offer a suggestion on how to define int?
This is one of two remaining problems to solve on a project that's
been dragging on for almost a year now. Once this is solved, I can
ship and pay my rent. So, I would be Oh, so greatful to solve this
in the next day or so. Sushi on me if you live in the tri-state as
soon as a sell a few of these.