views:

270

answers:

2

I want to create a landscape view with 2 table views side by side, using separate table controllers.

When I select a row, I want to move that selection to the other table. Initially I wanted an array, but I couldn't pass the array to the other controller. The array was a property of the table view controller.

I then tried to write the selection to core data, but that is crashing. To simplify, I have 2 entities in core data, Person (with name attribute and to one relationship) and SelectedPerson (with just the to one relationship to Person).

I have added the following:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    Person *person = (Person *)[fetchedResultsController objectAtIndexPath:indexPath];
    SelectedPerson *selectedPerson = [NSEntityDescription insertNewObjectForEntityForName:@"SelectedPerson"
                              inManagedObjectContext:managedObjectContext];
    [selectedPerson setValue:person forKey:@"persons"];
    [leftViewController.tableView reloadData];
    NSLog(@"Selection saved OK");

If I temporarily delete my left controller from the nib, this works fine and when I add it back, it opens with the selected persons. But with the left table view, I get the following crash log:

[49650:207] Record saved OK
[49650:207]-[Person compare:]: unrecognized selector sent to instance
[49650:207] Serious application error.  Exception was caught during Core Data change processing: -[Person compare:]: unrecognized selector sent to instance 0x3d33ef0 with userInfo (null)

***I have uploaded a sample application here link text

I've seen apps that use side by side tables, but I'm struggling to get this working. Any help would be greatly appreciated.

A: 

To update a table view, just send it a reloadData message.

Ole Begemann
Thanks for the reply. How do I send reloadData to a view that's already open with another view controller? Ie, 2 columns side by side, controlled by left view controller and right view controller. I want to add on didSelectRow on leftViewController a reload to the rightViewController.
`[rightViewController.tableView reloadData]` or however you call the property to your table view.
Ole Begemann
I apologize for my noobiness... what would be the line before this? If I'm creating a new controller I'd have something like... RightViewController *rightViewController = [RightViewController alloc]; Then your line would work and I'd push the controller. But in this case the controller is already open. How do I refer to the other controller?
Of course, you need to store a reference to the rightViewController somewhere so you can access it later. So your `LeftViewController` class should have a `rightViewController` property that you assign when you create the right view controller (either in code or via an IBOutlet from a NIB file).
Ole Begemann
I tried that (via IBoutlet) and while I can reload the tableview, I can't pass the array (which I set up as a property). I went back to the drawing board and wrote the selection to the datamodel, but it crashes as I'm updating the entity for the left tableview from my right tableview. (if I delete the left table from the nib, I can select entries that are saved to the model and shown if I return the table view and restart..only to crash if I try to to update it again).
Hmmm, I'd have to see all your code to know what's making it crash. (BTW, would you mind using backticks around code so that it gets `formatted` as such?)
Jonathan Sterling
Thanks for the feedback. I've corrected and added a sample application to see it in action
A: 

I figured it out - I didn't create controllerDidChangeContent in the right view controller.

I thought because I was updating a different entity than in the `fetchedResultsController', it wasn't needed but it turns out it is. Probably because of the inverse relationship. Thanks for the help.