The moment you update RecordVC.runsArray, I would assume that your tableview is already initialized and loaded, albeit without data.
What I did recently in this very situation is to use notifications.
In your RecordsViewController, you must register to be notified 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];
Also in RecordsViewController you will need a method that is called when a 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 does all this magic work 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];
Finally, you must clear and delete the notification in the RecordsViewController class. In your WillDisappear view, add the following line:
[[NSNotifcation defaultCenter] removeObserver:self name:@"runsArrayLoaded" object:nil];
Kerry source share