Invoking push segue programmatically and prepareforsegue method

Viewed 21189

I'm invoking push segue programmatically as below

    UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier:@"addToCartViewContollerForItem"];
    [self.navigationController pushViewController: vc animated:YES];

but my problem is I want to send some info with this segue to the destination viewcontroller. But the method - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender is not getting fired at all.

this is how the prepareforsegue method

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    NSLog(@"segue from deals screen");
    //addToCartViewContollerForItem
    if([[segue identifier] isEqualToString:@"addToCartSegue"]){
        NSIndexPath *selectedRow = [[self tableView] indexPathForSelectedRow];

        Item *currentItem = [[Item alloc]init];
        currentItem = [itemList objectAtIndex:[selectedRow row]];

        RESTAddToCartViewController *vc = [segue destinationViewController];
        [vc setCurrentItem:currentItem];
    }
}

What am I missing here?

2 Answers
Related