Error when trying to work with table view.

Anyone know why I am getting the following error with this code?

set theTable to data source of table view "tblView" of scroll view "tblView" of window "Backup"

The error you’re getting means that you’re referencing an object incorrectly. Either there’s a typo somewhere, or you’ve forgotten to name something.

Also, have you set up a data source? Table views don’t come with one by default, so you need to explicitly set one for it at some point in your code. I know that you don’t want to hear it, but the doc’s and examples have clear samples of how to do this.

Note that you can also manage a table view’s contents by setting it’s “content” as a list. This will automatically create a “data source” for the table, so you can start referencing it and it’s rows right way.

For example, here are some code bits that can be used with a list as a datasource…


property theTableView : ""
property theTableViewDataList : {}
property genericDataRow : {|NAME|:"Dude", |BIRTHDAY|:"6/6/06", |GIFT|:"Pitchfork"}

on awake from nib theObject
	if name of theObject is "Table" then
		set theTableView to theObject
		initialize()
		set content of theObject to theTableViewDataList
	end if
end awake from nib

on will close theObject
	if name of theObject is "Window" then
		(* Save the edit's you've made *)
		set theTableViewDataList to (content of theTableView) as list
		saveTheList()
	end if
end will close

on choose menu item theObject
	if name of theObject is "AddDataRow" then
		set theAction to (name of current menu item of theObject)
		
		if theAction is "Beginning" then
			tell data source of theTableView to set newDataRow to make new data row at beginning of data rows
			
		else if theAction is "End" then
			tell data source of theTableView to set newDataRow to make new data row at end of data rows
		end if

		set contents of data cell "NAME" of newDataRow to (|NAME| of genericDataRow)
		set contents of data cell "BIRTHDAY" of newDataRow to (|BIRTHDAY| of genericDataRow)
		set contents of data cell "GIFT" of newDataRow to (|GIFT| of genericDataRow)
		set selected data row of theTableView to newDataRow
	end if
end choose menu item

to initialize()
	set theTableViewDataList to {{|BIRTHDAY|:"6/6/06", |NAME|:"Dude", |GIFT|:"Pitchfork"}, {|BIRTHDAY|:"6/6/06", |NAME|:"Dude", |GIFT|:"Pitchfork"}, {|BIRTHDAY|:"6/6/06", |NAME|:"Dude", |GIFT|:"Pitchfork"}, {|BIRTHDAY|:"6/6/06", |NAME|:"Dude", |GIFT|:"Pitchfork"}}
end initialize

Working with table view’s and outline view’s can be very frustrating. They are very complex topics that need a lot of practice and understanding to work with effectively. If you’re using a simple list of data, then you should be able to get a pretty good implementation once you hammer out some of the reference details. Mastering data views using the official data source methods is quite difficult, especially when using complex data structures, so don’t run under the assumption that you’re just going to jump in and figure it out in one sitting. I agree, that the apple examples are not entirely explanatory of all that you need to know, but no one’s written anything better, so you’ll just have to piece it together for yourself. And as I said, the topic is far too complex to just explain to you, so you’ll have to give it a go and keep coming back for more answers when you get in a bind.

One thing I can’t recommend enough is starting small. Work on a small test project and get your features worked out thoroughly, and then transfer what you’ve learned over to your real project. Don’t get in over your head or you might just lose all interest and either compromise on an easier, less appropriate method… or you might just give up altogether.:frowning:

j

How do you do that? I thought I only had to add the table view to my window.