Tab views can be frustrating. :rolleyes:
That said, you have few options when it comes to manipulating object data and values for tab view items that are not the current one. The key I’ve found is to be very selective about how and when you reference the objects. Truthfully, you should only try to set data when you want to display it, which will eliminate some of your problem right there. The trick is finding a way to display the information after first making sure the tab view is selected.
Another thing that many people forget (largely due to the lack of decent documentation) is that the data source is an object NOT AT ALL dependent on the the object displaying it. A data source is an application-level object that can be managed regardless of the whether the object you want to display it in is visible… or even loaded from it’s nib. Rather than using a “set theDataSource to data source of theObject” to reference your data source, get in the habit of managing the data source directly (by name). Then, when you want something to display the data source you can simply tell it to use that data source.
For example, set up your data source in the application ‘launched’ handler…
on launched theObject
set theDataSource to make new data source at end of data sources with properties {name:"MyDataSource"}
tell theDataSource
make new data column at end of data columns with properties {name:"column1"}
set theRow to make new data row at the end of the data rows
set contents of data cell "column1" of theRow to "Test"
end tell
end launched
Then use handlers that only set the data source of your table view when you are certain that the object is in view. You can use the ‘selected tab view item’ handler of the tab view…
on selected tab view item theObject tab view item tabViewItem
if ((name of tabViewItem) as string) is "tab2" then
set theTableView to table view "tableView" of scroll view "scrollView" of tab view item "tab2" of tab view "tabs1" of window "window"
set data source of theTableView to data source "MyDataSource"
end if
end selected tab view item
Or you could use a control to manually set the current tab view item and THEN update the data source of the object…
on clicked theObject
if name of theObject is "tab2Button" then
tell tab view "tabs1" of window "window"
set the current tab view item to tab view item "tab2"
set theTableView to table view "tableView" of scroll view "scrollView" of tab view item "tab2"
end tell
set data source of theTableView to data source "MyDataSource"
end if
end clicked
There are lots of ways to provide workarounds to this tab view problem. Just make sure that you provide some ‘error-checking’ before asking an object known to be in a tab view to do something… and making it’s tab view item current if it’s not already.
Hope that helps (and is not too confusing ;))…
j