taskTable setDataSource


#1

First of al: Thank you for your great book. It makes it really easy for me to understand how the things are working together. Secondly sorry for my terrible english.

There is only one thing in this example i don’t understand. How does taskTable know the datasource, Is it because there is only one array and self is enough? And (when yes) how would it work, if there would be more than one array.

Thank you a lot
Claus


#2

taskTable knows its data source because we tell it what it is:

Basically a table view needs to know which object is acting as its data source, so by using [color=#008000]self[/color], we are saying that BNRAppDelegate will be its data source.

Also, by declaring the [color=#008000]UITableViewDataSource[/color] protocol in the BNRAppDelegate header file we must implement the method:
[color=#008000]tableView:cellForRowAtIndexPath:[/color]
and inside this method, to populate the cells within the table view with data we use

NSString *item = [tasks objectAtIndex:[indexPath row]]; [[c textLabel] setText:item];
which says that each cell of the table view contains an “item” (which is an NSString) from the “tasks” array.

Now, I am not sure exactly how to answer your question regarding “more than one array”, because as you see above we implicitly declare which array provides the data for the UITableViewCell’s, however if you wanted to supply more than one array as the data, then you would simply use some logic depending on what you actually wanted to achieve.

I hope this helps,
Nick
http://myfirstiphoneapp.co.uk
http://easyintervalsapp.co.uk


#3

I’m working through this example, and I’m having trouble when I type the line:

[taskTable setDataSource:self];

I get a warning that I’m sending 'BNRAppDelegate *const __strong" to parameter of incompatible type “id”

Pretty sure I’ve typed this all correctly, and the book does not seem to mention this warning.

Is this an expected warning?

Never mind! Doing the next step (adding the NSTableViewDataSource protocol in the .h file) fixed the warning.

Kim