0

I am trying to pass a string between two view controllers in a storyboard, core data program. The way I have it set up I want the next view to be pushed only for one section only. Hence the use of "didSelectRowAtIndexPath" rather than "prepareForSegue". Below is my code for "didSelectRow…" "five" is the viewController class being pushed.

- (void)tableView:(UITableView *)tableView
        didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    if (indexPath.section == 0)
    {
        five *five=[[five alloc]init];
        five.delegate = self;
        [self performSegueWithIdentifier:@"segue1" sender:self];
    }
}

"two" is the parent view. Below is the method used in a protocol created in the "five" class. "friendString" is in the "two" class and "fiveString" in "five". When the view is popped, the strings should be the same and then I use the string added in "five" in a UITextField in "two". However it doesn't update when the view is popped.

- (void)popFive:(five *)controller
{
    self.friendString=controller.fiveString;
    [self update];
    [self.tableView reloadData];
}

I believe the problem is related to how the seque is done in "didSelectRow…" Any help or ideas will be appreciated. Thanks.

TylerH4
  • 463
  • 1
  • 5
  • 12
  • I think when using "didSelectRow..." for a segue you also have to add the "prepareForSegue" method as well. Adding the below code seemed to make it work OK. – user1083689 Jun 11 '12 at 17:15

1 Answers1

0

I think when using "didSelectRow..." as a segue you also have to use "prepareForSegue". When I added this it seemed to be able to pass strings between the two view when the child view was popped. I included the code below

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

if (indexPath.section == 0)
{
    [self performSegueWithIdentifier:@"segue1" sender:self];
}

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{   

if ([segue.identifier isEqualToString:@"segue1"])
{
    five *five = segue.destinationViewController;
    five.delegate = self;

}   
}