0

i tried to push to detail view in storyboard, but is not working.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"drinkList"])
    {
        NSIndexPath *myIndexPath = [self.drinksCatTable indexPathForSelectedRow];

        if (myIndexPath.row ==0) //if selected is row 1 
        {
            selectedDrinkCat  =[segue destinationViewController];
            Drinks *drinkList = [aDelegate.categoryArray objectAtIndex:0];//forward all drinks to drinksList
            selectedDrinkCat.drinkList = drinkList;//point drinkList to the next view drinkList
            selectedDrinkCat.allDrinkStr = @"All";//all drinks selected 
                 NSLog(@"aaa");
        }
        else 
        {
            Drinks *drinkList = [aDelegate.categoryArray objectAtIndex:(myIndexPath.row)-1];//we have to minus 1 as the row had en extra "All" row which is not in the database
            selectedDrinkCat.drinkList = drinkList; 
            selectedDrinkCat.allDrinkStr =@"cat";
            NSLog(@"1111");

        }
    }
}

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

    [self performSegueWithIdentifier:@"drinkList" sender:self];
    NSLog(@"called did select");   

}

3 Answers 3

2

Shouldn't you declare selectedDrinkCat as a viewcontroller of the class of the destinationViewController?

Something like:

desmondViewController *selectedDrinkCat=(desmondViewController *)[segue destinationViewController];
0
0

You have to use the view controller's pushViewController: method.

0
0

Do the following:

  • Go to the storyboard file
  • click on viewcontroller1 then press on the main viewcontroller (mouse + ^) and drag it to the viewController2
  • from the context menu select push
  • a link will be created between these views, click on it and in the inspector change Indetifier to drinkList

This sets up the storyboard

Now the code you written should work.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.