PROBLEM IN MOVING VALUE FROM SECOND VIEW TO FIRST VIEW CONTROLLER IN IPHONE

sandy taylor

Total Post:46

Points:324
Posted by  sandy taylor
 608  View(s)
Ratings:
Rate this:

I have created an application in iPhone, I have two view controllers, to move second view controller I am using segue and set its identifier to 'MainViewController'.

In the second view I am using Table View Controller, I want to move first view controller at the time whenever I click on table view cell with cell value. because I am using this cell value in the label of second view controller, but I am unable to display that value in the first view controller.

This is the code of table view : didSelectedRowAtIndexPath:

-(void) tableView:(UITableView *)tableView didSelectedRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *key = [[animals allKeys] objectAtIndex:indexPath.section];
[self.delegate cellIsClicked:[[animals objectForKey:key] objectAtIndex:indexPath.row]];

UIViewController *controller = [self.navigationController.storyboard

instantiateViewControllerWithIdentifier:@"MainViewController"];
[self.navigationController pushViewController:controller animated:YES];
}

Please help me to solve this problem or tell me what is the problem in my code?
Thanks in advance!

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: Problem in moving value from second view to first view controller in iPhone

    You are colling pushViewController: method for navigation to other view controller,

    according to your need this is wrong because pushViewController is used to move next view controller but here our need is to come back to our previous view controller.

    so the best solution is that use navigationController's popViewControllerAnimated: method because this method will open the previous veiw controller.

    use like this:

    [self.navigationController popViewControllerAnimated:YES];

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!