简体   繁体   中英

How to push from Masterview to detail view with storyboard?

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");   

}

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

Something like:

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

您必须使用视图控制器的pushViewController:方法。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM