I have a UITableViewController with a button that triggers a modal flip horizontal segue animation to another UITableViewController. On the “flipside” I have a simple done button that dismisses the view if pressed. When dismissing the view I want to set the “test” string in MainTableViewController depending on what value the “test” string has in FlipsideViewController. I can’t get that connection working though. Posting my code below:
MainTableViewController.h
#import <UIKit/UIKit.h>
@interface MainTableViewController : UITableViewController
@property NSString *test;
@end
MainTableViewController.m
#import "MainTableViewController.h"
@interface MainTableViewController ()
@end
@implementation MainTableViewController
@synthesize test;
-(void)viewDidAppear:(BOOL)animated{
NSLog(@"%@", test);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return 1;}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return 10;}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"MainCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
FlipsideTableViewController.h
#import <UIKit/UIKit.h>
#import "MainTableViewController.h"
@interface FlipsideTableViewController : UITableViewController
- (IBAction)done:(id)sender;
@end
FlipsideTableViewController.m
#import "FlipsideTableViewController.h"
@interface FlipsideTableViewController ()
@end
@implementation FlipsideTableViewController
- (IBAction)done:(id)sender{
NSString *test = @"Hello!";
// Push the test string to MainTableViewController
[self dismissViewControllerAnimated:YES completion:nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return 1;}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return 10;}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"FlipsideCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
@end
Use delegate for backward passing of data
Refer simple-delegate-tutorial-for-ios-development link.
Also refer basic-delegate-example link too.