Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: table view YEARGH!!! was: search table view revisited



Ah, ok, now I understand what's happened with the emails!

re. your "first weirdness". The code I offered, and which you have based your code on, WON'T behave as you want it to with SORTED data sources. I hadn't realised that you were working with a sorted data source (my bad - should have thought about that one and checked with you whether you were using sorted or unsorted data sources).

The code assumes, as it were, that the data in the data source is in the same order as the data is displayed in the table view. It finds an index (position) in the data source and then selects the corresponding row index in the table. That's fine if the two are in the same order. But if you have a sorted data source, then the index (position) in the data source almost certainly won't correspond to the row index in the table view. In the code the line "set columnContents to get contents of data cell thecellvalue of every data row of data source ..." gets the values of a column of data. That list of values will be in the order that the data rows were created in the data source, not in the sorted order that they are displayed in the table view.

What we need is the list of column values in the sorted order. I don't think it is possible to get that in one step. I think we have to get the sorted data rows and then loop through them getting the values of the data cell we want. The key is the property of a data source: sorted data rows. This is from the documentation:

sorted data rows
     Access: read only
     Class: list
 the data rows of the data source in its currently sorted order

So this is how your code should be adapted to work with a sorted data source:

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 sortedDataRows to get sorted data rows of (data source of table view 1 of scroll view 1 of window MyTableView)
    repeat with i from 1 to count of sortedDataRows
        set thisSortedDataRow to item i of sortedDataRows
        if (get content of data cell thecellvalue of thisSortedDataRow) is theitem then
            exit repeat
        end if
    end repeat
    set selected row of  table view 1 of scroll view 1 of window MyTableView to i
    call method "scrollRowToVisible:" of object (table view 1 of scroll view 1 of window MyTableView) with parameter (i - 1)
end if

If one of your data sources is sorted and the other isn't, I'd suggest splitting the code so that you use the original code for the unsorted one and this code for the the sorted one.

Also, incidentally, I think you would find your code much easier to write if you created and named your data sources and then assigned them to the table views:

    set dataSource to make new data source at end of data sources with properties {name:"xyz"}

then

    set data source of table view .... to data source "xyz"

One of the beauties of data sources is that they can be referenced from anywhere by name - you don't have to constantly reference them backwards from a table view. You can just say:

    data source "xyz"

not

    data source of table view ...

You might also, again for simplicity's sake, assign references to objects to variables. You are saying:

    table view 1 of scroll view 1 of window MyTableView

why not say, for instance:

    set tableOne to table view 1 of scroll view 1 of window "abc"
    set tableTwo to table view 1 of scroll view 1 of window "def"

Then you can just say things like

    set selected row of tableOne to ...

instead of

    set selected row of  table view 1 of scroll view 1 of window MyTableView to ...

Just a thought.

Philip



On Sat 10/05/08 12:16 AM , Joshua Whalen email@hidden sent:
This message was posted to the list several days ago. So sorry for
making a mess and taking so long to correct it, I'm having equipment
problems too, now.

The message was bounced because of embedded graphics. I've
substituted links in their place. Hope it works!

Thanks again, all.

Joshua

===============================================
Begin reposted message:
===============================================



AIIEEEE!!!

Hello friends.

Well, first of all, I just want to say, thank you Philip for all your
efforts on my behalf.

Your function works beautifully, but...

Something weird (several somethings, actually...) is happening, but I
suspect there is probably a simple answer.

Observe:

below is my app. As you can see, I've told it to search for a
playlist called "Clash"

Now, when I did this the log file returned:

2008-05-07 21:02:07.971 RadioKnife 1.0[542] "Clash this is the search
item in searchme

"
2008-05-07 21:02:08.013 RadioKnife 1.0[542] "Schedule is the window
that was called

"
2008-05-07 21:02:08.070 RadioKnife 1.0[542] {6, " here's theindex!", "
", "
"}
2008-05-07 21:02:08.109 RadioKnife 1.0[542] {7, " This is the
selected row's index.", "
", "
"}
2008-05-07 21:02:08.149 RadioKnife 1.0[542] {16, " This is myIDNum", "

Not exactly as we'd expect from this ( I hope I haven't screwed up
here somewhere) code:

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 (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)
log (theIndex + 1) & " This is the selected row's index." & return
& return
update (table view 1 of scroll view 1 of window MyTableView)
set MyIDNum to get id of the selected data row of table view 1 of
scroll view 1 of window MyTableView
log MyIDNum & " This is myIDNum" & return & return
end if

This is what the app does:

(See http://www.panix.com/~joshua/help1.html">this link
for the image.)

The app searches one of two tables. Here's what happens when the
exact same code searches the other table:
(the little chevron thingy is some kind of artifact. It's not there
in the actual search text, just in the snapshot)

(See http://www.panix.com/~joshua/help2.html">this link
for the image.)

Heres the log data:

2008-05-07 21:03:10.453 RadioKnife 1.0[542] "Clash this is the search
field content

"
2008-05-07 21:03:10.492 RadioKnife 1.0[542] "Clash this is the search
item in searchme

"
2008-05-07 21:03:10.643 RadioKnife 1.0[542] {19, " here's theindex!", "
", "
"}
2008-05-07 21:03:10.688 RadioKnife 1.0[542] {20, " This is the
selected row's index.", "
", "
"}
2008-05-07 21:03:10.732 RadioKnife 1.0[542] {30, " This is myIDNum", "
", "

Huh?

Anyway....

That's the first set of weirdnesses. Here's the two sets of code that
generate the two different tables:

The first table:

on MakeATable() -- creates the table in tableview 1 of window "main"
try
set theDataSource to data source of table view 1 of scroll view 1
of window 1
tell theDataSource
if (count data columns) = 0 then
make new data column at end of data columns with properties
{name:"airtime", sort order:ascending, sort type:numerical, sort case
sensitivity:case sensitive}
make new data column at end of data columns with properties
{name:"showname", sort order:ascending, sort type:alphabetical, sort
case sensitivity:case sensitive}
make new data column at end of data columns with properties
{name:"endtime", sort order:ascending, sort type:numerical, sort case
sensitivity:case sensitive}
make new data column at end of data columns with properties
{name:"fader", sort order:ascending, sort type:numerical, sort case
sensitivity:case sensitive}
make new data column at end of data columns with properties
{name:"willendat", sort order:ascending, sort type:numerical, sort
case sensitivity:case sensitive}

-- Make this a sorted data source
set sorted of theDataSource to true

-- Set the "name" data column as the sort column
set sort column of theDataSource to data column "airtime" of
theDataSource
end if
end tell
end try
end MakeATable


on SetTableContent(MyShowData) -- sets the contents of the table
created by the makeatable subroutine
try
tell data source of table view 1 of scroll view 1 of window 1
set theNewRow to make new data row at end of data rows
set contents of data cell 1 of theNewRow to (airtime of
MyShowData) as date
set contents of data cell 2 of theNewRow to (showname of MyShowData)
set contents of data cell 3 of theNewRow to (endtime of MyShowData)
set contents of data cell 4 of theNewRow to (fadetime of MyShowData)
set contents of data cell 5 of theNewRow to (willendat of
MyShowData) as date
return theNewRow
end tell
end try
end SetTableContent


the second table:

set content of table view "playlist" of scroll view "playlist" of
window "chooseplaylist" to every text item of ShowList


I should mention that the contents of the first table are subject to
frequent reordering. Rows are added, deleted, edited, and sorted
constantly.

Okay, Weirdness number two:

Once I search for something, the table view is locked. What I mean by
that is this:

In both tables, users can either click an appropriate button or else
double click a selection to bring up a schedule & settings dialog.
Once the search function has been run, double clicking ceases to
function in table 1 for the duration of the session, or in table 2
for the duration of the action (that is, once you've made a choice
and dismissed the playlist-picker, the table ceases to be, and
doesn't get recreated until you call it again, when it works fine again.

A clue as to how to fix that would be helpful.

So sorry to use so much of the list's time. I'm really grateful for
all your help, and look forward to celebrating when I finish this (a
few days once this and one other problem are solved).

CU!
TIA,

Joshua


Joshua Whalen
email@hidden
email@hidden
http://www.panix.com/~joshua/resume.html


"Vision without action is a day dream,
Action without vision is a nightmare."
-- Japanese proverb



_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Studio mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden



Message sent via KC WebMail - http://webmail.mistral.net/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Studio mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.