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 4622542
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:51:30+00:00 2026-05-22T02:51:30+00:00

I have a view controller class called PresidentsViewController that sets up data in a

  • 0

I have a view controller class called PresidentsViewController that sets up data in a UITableView. This data is in the form of NSMutableArray called list. I have another class, PresidentAddController, that is supposed to handle adding an object of type President to this list based on user inputted data about a president. However, I can’t get the object to add to the list. I have confirmed that the user inputted data for a new president is being collected correctly, so it is adding to the list that’s in another class that’s causing problems. I believe the correct code to add an object to the list is:

[pvc.list addObject:newPresident];

However, I don’t know how to properly create the reference/instance/? (which is what pvc would be) to PresidentsViewController inside of PresidentAddController so that I can properly add a new president to the list. I am not using Interface Builder for this because it is just a UITableView.

How do I add a president to the list in this situation?

Edit: Here is how the array is being initialized:

@property (nonatomic, retain) NSMutableArray *list;

And here is how PresidentAddController is being set up in PresidentsViewController:

PresidentAddController *childController = [[PresidentAddController alloc] initWithStyle:UITableViewStyleGrouped];
childController.title = @"Add President";
[self.navigationController pushViewController:childController animated:YES];
[childController release];
  • 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-22T02:51:30+00:00Added an answer on May 22, 2026 at 2:51 am

    Add a pointer to PresidentAddController this way:

    // in @interface
    PresidentsViewController *listController;
    
    @property (nonatomic, assign) PresidentsViewController *listController;
    
    // in @implementation
    @synthesize listController;
    

    Then when you instantiate your PresidentAddController, set the pointer:

    PresidentAddController *childController = 
      [[PresidentAddController alloc]
       initWithStyle:UITableViewStyleGrouped];
    childController.title = @"Add President";
    childController.listController = self;
    [self.navigationController pushViewController:childController animated:YES];
    [childController release];
    

    So then you can go [listController.list addObject:newPresident]; in PresidentAddController.

    EDIT: childController.listController = self calls [childController setListController:self], which in turn reads the @synthesized method in your implementation and sets the pointer *listController to point to the current class (if you’re writing code in the PresidentsViewController class, then self is going to be the current instance of PresidentsViewController).

    The reason why I use assign is because if you were to use retain, then when you set listController to self it will actually keep an owning reference to the object. This can cause all sorts of problems if you ever try to deallocate PresidentsViewController, because if you have an owning reference in PresidentAddController then it will not deallocate until that reference is also released. Using assign ensures that if you ever release the PresidentsViewController before PresidentAddController disappears, it will be properly deallocated. Of course, maybe you want to keep it around in that situation, in which case using retain here is also fine.

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

Sidebar

Related Questions

I have a class called Chair. I have a view controller that contains an
The goal is to have a singleton data controller class called FetchData.h/.m that pulls
I have a view controller class that has to implement several protocols. Too keep
I have the problem that my view controller class has too many delegates and
I have a view controller that gets presented modally and changes some data that
Ok heres the situation. I have a View controller class that serves as the
I have this code in my table view controller (and delegate): - (void)tableView:(UITableView *)tableView
I have a TableView controller class that uses a fetched results controller to display
I have a View Controller inside my MainWindow.xib file that loads the nib Cover
I have a login function in my controller that was getting called before, but

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.