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

  • SEARCH
  • Home
  • 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 8135173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:19:52+00:00 2026-06-06T10:19:52+00:00

I have a main view controller that consists of 1 button that when tapped,

  • 0

I have a main view controller that consists of 1 button that when tapped, pushes a detail view controller and another button that simply launches a modal view controller that has a table. This detail view controller has a button that when tapped should add a new object to the array that was loaded by the table in the modal view controller.

Problem is, that add a new object button doesn’t add to the NSMutableArray.

When I put a button in the main view and assigned the same method of adding objects to the NSMutableArray, it works. It just doesn’t work when the button is placed on another view controller presented either via Navigation Controller and Modal View.

Here’s my code when the button is pressed in the detail view controller:

- (IBAction)confirmBtnPressed
{
    // Gets the current time and formats it
    NSDate *timeNow = [NSDate date];
    NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
    [timeFormatter setDateFormat:@"hh:mm a"];

    // Gets the current date and formats it
    NSDate *dateNow = [[NSDate alloc] init];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"MMM dd, yyyy"];

    NSString *currentTime = [timeFormatter stringFromDate:timeNow];
    NSString *currentDate = [dateFormatter stringFromDate:dateNow];
    NSString *timestamp = currentTime;
    NSString *date = currentDate;

    // This is where values gets saved
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:timestamp       forKey:kTimeStampText];
    [defaults setObject:date            forKey:kDateText];
    [defaults synchronize];

    NSString *timeToday = [defaults objectForKey:kTimeStampText];
    NSString *dateToday = [defaults objectForKey:kDateText];

    tableVC.tableDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:timeToday, @"Time", dateToday, @"Date", nil];
    [tableVC.tableArray addObject:tableVC.tableDict];
    [tableVC.table reloadData];
}

Here’s my code in the main view controller when the button to load the table modally is pressed:

// Table loaded
- (IBAction)viewHistoryPressed:(id)sender
{
    if (!self.historyViewController)
    {
        self.historyViewController = [[HistoryViewController alloc] initWithNibName:@"HistoryViewController" bundle:nil];
    }

    [self presentModalViewController:historyViewController animated:YES];
}

Here’s my viewDidLoad in my table view controller:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *time = [defaults objectForKey:kTimeStampText];
    NSString *date = [defaults objectForKey:kDateText];

    tableDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:time, @"Time", date, @"Date", nil];

    tableArray = [[NSMutableArray alloc] initWithObjects:tableDict, nil];
}

Screenshot of the main view:

enter image description here

detail view:

enter image description here

table view:

enter image description here

  • 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-06-06T10:19:58+00:00Added an answer on June 6, 2026 at 10:19 am

    in viewDidLoad method… please use self.tableDict and self.tableArray while allocating them. ‘self’ calls the getter and setter methods so it is imp.

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

Sidebar

Related Questions

I have a modal view controller that is presented from my main view, I
I have a regular old iPhone app that has a main view controller that
I'm developing an iOS 4 application. I have a main view that contains another
I have a main view controller that takes care of the drawing for my
Situation: In the main View Controller, I have a UIScrollView and within that I
I'm using codeigniter and have a main view that calls another view based on
My application has a view controller that extends UITableViewController . The initialization method looks
I have this code in the main view controller and it is working just
I have one main view with an associated controller. I have some rather complicated
i have a main view controller with two subview in it,one is note-view and

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.