Bharat
Bharat

Reputation: 3007

prepareForSegue function not called with delegate?

I have added a UITableViewController with static cells. I have a bar button 'save', but when I click on the button, the prepareForSegue method is not called at all. Here is my code:

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"AddCustomer"]) {
        UINavigationController *navigationController = segue.destinationViewController;
       AddCustomersViewController *addCustomersViewController = [[navigationController viewControllers] objectAtIndex:0];
        addCustomersViewController.delegate = self;
    }
}

and here is my delegates method

 -(void) customerDidSave:(AddCustomersViewController *)controller newCostomer:(Customers *)customer
    {
        [self dismissViewControllerAnimated:YES completion:nil];
        [self.customers addObject:customer];
        [self.tableView reloadData];
    }

I don't know what is the problem. Any ideas?

Upvotes: 0

Views: 1181

Answers (2)

Jonathan King
Jonathan King

Reputation: 1528

Replace with;

if ([segue.identifier isEqualToString:@"AddCustomer"]) {
[[segue destinationViewController] setDelegate:self];
    }

This is unnecessary, and probably what is causing the problems - [[navigationController viewControllers] objectAtIndex:0]

Upvotes: 0

deleted_user
deleted_user

Reputation: 3805

Yeah, your segue is not connected to the view controller class in IB, or the clas name of the view controller is not set to your view controller class

Upvotes: 1

Related Questions