我试图在故事板中推送到详细视图,但是无法正常工作。
-(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");
}
答案 0 :(得分:2)
您不应该将selectedDrinkCat
声明为viewcontroller
的{{1}}类吗?
类似的东西:
destinationViewController
答案 1 :(得分:0)
您必须使用视图控制器的pushViewController:
方法。
答案 2 :(得分:0)
执行以下操作:
storyboard
文件viewcontroller1
,然后按主视图控制器(鼠标+ ^)并将其拖至viewController2
Indetifier
更改为drinkList
这会设置故事板
现在你编写的代码应该有效。