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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:32:06+00:00 2026-06-14T15:32:06+00:00

I have 2 TableViewControllers. When the user taps a UIBarButtonItem, It saves the text

  • 0

I have 2 TableViewControllers. When the user taps a UIBarButtonItem, It saves the text from a UITextField, runnameField, in SaveViewController. It should take runnameField’s text and put it in an array, runsArray. In RecordVC, the tableView’s data should come from runsArray.
Can someone please help me with this? I’ve been googling for a long time and can’t find any answers.

SaveViewController.h:

#import <UIKit/UIKit.h>
#import "RecordsViewController.h" //Next ViewController

@interface SaveViewController : UITableViewController <UITableViewDataSource,UITableViewDelegate> {
__weak IBOutlet UITextField *runnameField;
RecordsViewController *RecordsVCData;
}
@property (weak, nonatomic) IBOutlet UITextField *runnameField;
@property (weak, nonatomic) IBOutlet UITextView *runnotesTextView;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *saveBarItem;
@property (nonatomic, retain) RecordsViewController *RecordsVCData;

- (IBAction)saverun:(UIBarButtonItem *)sender;
- (IBAction)goAwayKeyboard:(id)sender;



@end

SaveViewController.m:

- (IBAction)saverun:(UIBarButtonItem *)sender {
RecordsViewController *RecordsVC = [[RecordsViewController alloc] initWithNibName:nil bundle:nil];
RecordsVC.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
self.RecordsVCData = RecordsVC;
[RecordsVC.runsArray addObject:[NSString stringWithFormat:@"%@", runnameField.text]];
[self presentModalViewController:RecordsVC animated:YES];
}

- (IBAction)goAwayKeyboard:(id)sender {
    [sender resignFirstResponder];
}

RecordsViewController.h:

#import <UIKit/UIKit.h>
@interface RecordsViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate> {      
NSMutableArray *runsArray;
}
@property (weak, nonatomic) NSString *runname;
@property (strong, nonatomic) NSString *runnotes;
@property (weak, nonatomic) UITableViewCell *cell;
@property (retain,nonatomic) NSMutableArray *runsArray;
@end

RecordsViewController.m:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:     (NSIndexPath *)indexPath {

// Identifier for retrieving reusable cells.
static NSString *cellIdentifier = @"MyCellIdentifier";

// Attempt to request the reusable cell.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault     reuseIdentifier:cellIdentifier];
// No cell available - create one
if(cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                  reuseIdentifier:cellIdentifier];
[cell.textLabel setText:[NSString stringWithFormat:@"%@",[runsArray objectAtIndex:indexPath.row]]];

}

// Set the text of the cell to the runnamestring.
[cell.textLabel setText:[NSString stringWithFormat:@"%@",[runsArray objectAtIndex:indexPath.row]]];
return cell;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [runsArray count];
}

Any help is appreciated a ton.

Thanks,

Dhruv

  • 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-14T15:32:08+00:00Added an answer on June 14, 2026 at 3:32 pm

    At the point where you are updating RecordsVC.runsArray, I would imagine your tableview has already been initialized and loaded, albeit with no data.

    What I have done recently in this very situation is to use notifications.

    In your RecordsViewController, you would register for a notification in your init method:

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
    
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dataLoaded:) name:@"runsArrayLoaded" object:nil];
    
            // Custom initialization
        }
        return self;
    }
    

    Also in the RecordsViewController, you will need the method that gets called when the notification is received. In this case, it is dataLoaded:

    -(void) dataLoaded:(NSNotification *)notif {
        if (notif.userInfo){
            runsArray = [notif.userInfo objectForKey:@"newdata"];
            [self.tableview reloadData];
        }
    }
    

    The part that makes all this magic works is in your saverun method inside the SaveViewController class.

    - (IBAction)saverun:(UIBarButtonItem *)sender {
        RecordsViewController *RecordsVC = [[RecordsViewController alloc] initWithNibName:nil bundle:nil];
        RecordsVC.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        [runsArray addObject:[NSString stringWithFormat:@"%@", runnameField.text]];
        [self presentModalViewController:RecordsVC animated:YES];
    
        // notify the RecordsViewController that new data is available
        NSMutableDictionary* userInfo = [[NSMutableDictionary alloc] initWithCapacity:1];
        [userInfo setObject:runsArray forKey:@"newdata"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@runsArrayLoaded" object:nil userInfo:(NSDictionary*)userInfo];
    }
    

    Finally, the you must clean up and remove the notification observation in the RecordsViewController class. In your viewWillDisappear, add the following line:

    [[NSNotifcation defaultCenter] removeObserver:self name:@"runsArrayLoaded" object:nil];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TableView that is populated with data. When a user taps a
I have a TableViewController with x rows. When the user taps on one row
I have two TableViewControllers with a segue in-between. When a user clicks on a
I have a uitableview that is populated from a sqlite query. I want to
I have a NavigationController -> UIViewController -> UIWebView I have a modal segue from
i have added a UIPopover to my navigationbar when the user touches the rightbarbuttonitem.
Is it possible to have two NavigationControllers managing two TableViewControllers at the same time
I have a tableview where each cell is populated with dynamic data from an
I have a workflow in my app where the user will build a compound
I have some TableViewController with static Cells and some TextFields. A few Days ago,

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.