0

I'm new with xcode ios programming i have 2 table view controllers and i want to pass object from child to parent controller. It is easy if pass from parent to child, but i can't find a simple way to pass object back from child to parent controller after a row in child view is selected.

Note: *searchFieldController is the parent controller

parent header file

@interface ProductSearchFieldTableViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>

@property(strong, nonatomic) NSString *selectedMake;

@end

parent implement file

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    // Configure the cell...
    NSDictionary *field= [self.fields objectAtIndex:indexPath.row];
    NSString *name=[field objectForKey:@"name"];
    if([name isEqualToString: @"make"]){
        [self performSegueWithIdentifier:@"valueSeque" sender:self];
    }
}

Child implement file

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ProductSearchFieldTableViewController *searchFieldController = [ProductSearchFieldTableViewController alloc];
    searchFieldController.selectedMake =[[fields objectAtIndex:indexPath.row] objectForKey:@"value"];

    [self.navigationController popViewControllerAnimated:YES];   
}
Khean
  • 99
  • 1
  • 13
  • Create a property of Parent Controller in child's controller and use it by its reference. – iphonic Oct 27 '14 at 05:32
  • This is a situation where one usually uses a delegate protocol. – rdelmar Oct 27 '14 at 05:51
  • You're creating a new instance of ProductSearchFieldTableViewController instead of accessing your parent. Besides, you shouldn't look into parentViewController as this isn't your case. You should instead implement a delegate, as suggested by @rdelmar – Andrei Filip Oct 27 '14 at 16:15
  • thank you i use delegate method :) – Khean Oct 28 '14 at 03:08

1 Answers1

0

There are many answers for this question already on StackOverflow.

Some links to answer your question:

How to Pass Data Back

Passing Data between View Controllers

Community
  • 1
  • 1
anthonyliao
  • 1,314
  • 1
  • 8
  • 8