如何使用故事板从主视图推送到详细视图?

时间:2012-06-02 13:54:33

标签: iphone ios xcode uistoryboard

我试图在故事板中推送到详细视图,但是无法正常工作。

-(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 个答案:

答案 0 :(得分:2)

您不应该将selectedDrinkCat声明为viewcontroller的{​​{1}}类吗?

类似的东西:

destinationViewController

答案 1 :(得分:0)

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

答案 2 :(得分:0)

执行以下操作:

  • 转到storyboard文件
  • 点击viewcontroller1,然后按主视图控制器(鼠标+ ^)并将其拖至viewController2
  • 从上下文菜单中选择推送
  • 将在这些视图之间创建一个链接,点击它并在检查器中将Indetifier更改为drinkList

这会设置故事板

现在你编写的代码应该有效。