views:

51

answers:

1

The short version: Is there a way to populate one specific row in a tableView with one value from one array, then populate another row in that same tableView with one value from a different array? For example, cell 1 would have the first value from Array A, cell 2 would have the first value from Array B, cell 3 would have the first value from Array C, etc.

The long version: I hope this isn't too confusing. I've got an array of names, and then three more arrays with actions associated with those people. For example, the names array has Jim, Bob, and Sue, and then there's an array for eating, reading, and sleeping that records every time each person does one of these things (all of these arrays are populated from a MySQL database). The names array is used to populate a root tableView. Tapping on one of the names brings up a detail view controller that has another tableView that only has three rows. This part is all working fine.

What I want to happen is when I tap on a name, it moves to the detail view and the three cells would then show the last event for that person for each of the three activities. Tapping on one of those three events then moves to a new view controller with a tableView that shows every event for that category.

For example, if I tapped on Bob, the second page would show the last time Bob ate, read, and slept. Tapping on the first row would bring up a table that showed every time Bob has eaten.

So far I've only been able to populate the second tableView with all of the rows from one of the arrays. I need it the other way around (one row from all of the arrays).

+1  A: 

Absolutely. The steps would involve putting the right code in two methods for your second tableView:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

and

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

Your numberOfRowsInSection method would just return 3, since there will only be three rows, and your cellForRowAtIndexPath will examine its indexPath parameter to see if it is 0, 1, or 2 (all of the possible values). If it's zero, fill the cell with the appropriate data from the eating array. If it's one, fill it from the reading array. And if two, fill it from the sleeping array. Or whatever order is appropriate.

Drew C