Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3982476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:31:56+00:00 2026-05-20T05:31:56+00:00

First of all, thank God for Stack Overflow. I am new at Objective-C/Cocoa/iPhone development,

  • 0

First of all, thank God for Stack Overflow. I am new at Objective-C/Cocoa/iPhone development, and this site is an amazing aid.

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:

InvoiceAddViewController *addController = [[InvoiceAddViewController alloc] initWithNibName:@"InvoiceAddViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:addController animated:YES];

This table view controller pushes it’s own detail view:

    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];

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.

In order to push data back, I created a method on the “Add” UITableViewController:

- (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;
    }
}

This method is designed to receive the data I push with this method in “Generic”:

- (IBAction)saveField:(id)sender
{
    self.fieldValue = theTextField.text;
    InvoiceAddViewController *parentController = (InvoiceAddViewController*)self.view.superview;
    [parentController updateField:self.fieldName value:self.fieldValue];
}

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.

I have tried the following combinations (from GDB):

(gdb) po [[self view] superview]
<UIViewControllerWrapperView: 0x4b6d4d0; frame = (0 64; 320 367); autoresize = W+H; layer = <CALayer: 0x4b6c090>>
(gdb) po [[self navigationController] parentViewController]
<UITabBarController: 0x4d2fa90>
(gdb) po [self parentViewController]
<UINavigationController: 0x4d2fdc0>

I feel like I’m landing all around the UITableView I want to invoke, but can’t find it.

What am I doing wrong?

refrains from pulling more hair out

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:31:56+00:00Added an answer on May 20, 2026 at 5:31 am

    The problem is that you are confusing the view hierarchy for the navigation stack. Your detail view controller wants to send a message to the controller that pushed it on the stack, which is the second to last object in the navigation controller’s viewControllers array.

    Try changing your saveField: method to:

    - (IBAction)saveField:(id)sender
    {
        self.fieldValue = theTextField.text;
        NSArray *navigationStack = self.navigationController.viewControllers;
        InvoiceAddViewController *parentController = (InvoiceAddViewController*)[navigationStack objectAtIndex:navigationSTack.count - 2];
        [parentController updateField:self.fieldName value:self.fieldValue];
    }
    

    Edit: I should note this design is very brittle. A better way is to apply Model-View-Controller and create an object that represents a field and title value. Then your InvoiceAddViewController can pass instances of these objects to your detail controller, and as your detail controller changes them, these changes can be easily reflected in your other controllers.

    Edit 2: Here is a hint of how it will work.

       UITableViewCell *targetCell = [self.tableView cellForRowAtIndexPath:indexPath];
    
        GenericTextFieldDetailViewController *dvController = [[GenericTextFieldDetailViewController alloc] initWithNibName:@"GenericTextFieldDetailViewController" bundle:[NSBundle mainBundle]];
    
        dvController.dataObject = [self dataObjectForIndexPath:indexPath];
        [self.navigationController pushViewController:dvController animated:YES];
        [dvController release];
    

    I’m assuming you’ve implemented a dataObjectForIndexPath: method. Presumably tableView:cellForRowAtIndexPath: would also use this method to configure its cells.

    Now, you can eliminate both the saveField: and updateField: methods. In your InvoiceAddViewController, viewWillAppear: could be used to refresh your view like this:

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        [self.tableView reloadData]
    }
    

    There is a whole world of possibilities here. reloadData is a very heavy handed one. Experiment with stuff like KVO to make this more automatic.

    In your detail controller, of course, don’t forget to update the object, say in view will disappear to do something like

    self.dataObject.fieldValue = theTextField.text;
    

    This is just to get you started. There are a lot of possibilities and details to consider. You should really look at a lot of sample code, this pattern gets used a lot. The CoreDataBooks example on the developer portal uses a similar pattern, there are almost certainly others.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first of all thank you all for reading this. i want to populate my
First of all I would like to thank all of the contributors of this
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
First of all (in case this is important) I'm using ActiveState's Perl (v5.8.7 built
First of all there is a partial question regarding this, but it is not
First of all, let me say I am very new to rails, have been
First of all, thank you very much in advance for any attempt at helping
first of all, I am new to silverlight(play around with it for one month)
First of all this is homework. I have been trying to get rid of
This is my first post, so first of all I want to say a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.