Note that there are some explanatory texts on larger screens.

plurals
  1. POSending data from my detail view back to my UITableView
    primarykey
    data
    text
    <p>First of all, thank God for Stack Overflow. I am new at Objective-C/Cocoa/iPhone development, and this site is an amazing aid.</p> <p>I have a window, that has a tab bar, that has a navigation controller, that loads a UITableViewController. Clicking an "Add" button on the navigation bar (created programatically), pushes a UITableViewController like so:</p> <pre><code>InvoiceAddViewController *addController = [[InvoiceAddViewController alloc] initWithNibName:@"InvoiceAddViewController" bundle:[NSBundle mainBundle]]; [self.navigationController pushViewController:addController animated:YES]; </code></pre> <p>This table view controller pushes it's own detail view:</p> <pre><code> UITableViewCell *targetCell = [self.tableView cellForRowAtIndexPath:indexPath]; GenericTextFieldDetailViewController *dvController = [[GenericTextFieldDetailViewController alloc] initWithNibName:@"GenericTextFieldDetailViewController" bundle:[NSBundle mainBundle]]; dvController.fieldName = targetCell.textLabel.text; dvController.fieldValue = targetCell.detailTextLabel.text; [self.navigationController pushViewController:dvController animated:YES]; [dvController release]; </code></pre> <p>The concept being, you click on a cell in the table view controller such as "Notes". This pushes "GenericTextFieldDetailViewController" with the name of the "field" you clicked, and the value (if one already exists). This allows me to reuse my detail view rather than creating one ad nauseum for every field.</p> <p>In order to push data back, I created a method on the "Add" UITableViewController:</p> <pre><code>- (void) updateField:(NSString*) fieldName value:(NSString*) fieldValue { UITableViewCell *targetCell; if([fieldName isEqualToString:@"Invoice ID"]) { NSUInteger indexArr[] = {1,1}; targetCell = [[self tableView] cellForRowAtIndexPath:[NSIndexPath indexPathWithIndexes:indexArr length:2]]; targetCell.detailTextLabel.text = fieldValue; } else if([fieldName isEqualToString:@"P.O. Number"]) { NSUInteger indexArr[] = {1,2}; targetCell = [[self tableView] cellForRowAtIndexPath:[NSIndexPath indexPathWithIndexes:indexArr length:2]]; targetCell.detailTextLabel.text = fieldValue; } else if([fieldName isEqualToString:@"Add Note"]) { NSUInteger indexArr[] = {3,0}; targetCell = [[self tableView] cellForRowAtIndexPath:[NSIndexPath indexPathWithIndexes:indexArr length:2]]; targetCell.detailTextLabel.text = fieldValue; } } </code></pre> <p>This method is designed to receive the data I push with this method in "Generic":</p> <pre><code>- (IBAction)saveField:(id)sender { self.fieldValue = theTextField.text; InvoiceAddViewController *parentController = (InvoiceAddViewController*)self.view.superview; [parentController updateField:self.fieldName value:self.fieldValue]; } </code></pre> <p>Which brings us to the problem: When the save method fires off, it throws an invalid selector error because self.view.superview is not the UITableView that pushed the "Generic" detail view.</p> <p>I have tried the following combinations (from GDB):</p> <pre><code>(gdb) po [[self view] superview] &lt;UIViewControllerWrapperView: 0x4b6d4d0; frame = (0 64; 320 367); autoresize = W+H; layer = &lt;CALayer: 0x4b6c090&gt;&gt; (gdb) po [[self navigationController] parentViewController] &lt;UITabBarController: 0x4d2fa90&gt; (gdb) po [self parentViewController] &lt;UINavigationController: 0x4d2fdc0&gt; </code></pre> <p>I feel like I'm landing all around the UITableView I want to invoke, but can't find it. </p> <p>What am I doing wrong?</p> <p><em>refrains from pulling more hair out</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload