我对 xcode 很陌生,我正在尝试开发一个示例应用程序,它基本上是一个具有多个级别的嵌入式 tableview。我有一个 plist 存储每个 tableview 的单元格。如果单元格没有孩子,那么我希望能够在按下单元格后转到一个详细视图。最终,我希望能够根据数据类型转到不同的详细视图。为此,我从情节提要创建了一个详细视图,将视图控制器拖到我的详细视图以创建手动“Push”segue,并将 segue 标记为“segue1”。
编辑:这里的源代码
接下来,我填充了我认为它工作的必要函数,即调用[self performSegueWithIdentifier:@"segue1" sender:myString];
myString 是我选择的单元格的标题。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Check the dictionary to see what cell was clicked
NSDictionary *dict = [self.tableDataSource objectAtIndex:indexPath.row];
NSString *myString = [dict objectForKey:@"Title"];
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
NSArray *children = [dictionary objectForKey:@"Children"];
//If there is no children, go to the detailed view
if([children count] == 0)
{
[self performSegueWithIdentifier:@"segue1" sender:myString];
}
else{
//Prepare to tableview.
DrillDownViewController *rvController = [[DrillDownViewController alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
//Increment the Current View
rvController.CurrentLevel += 1;
//Set the title;
rvController.CurrentTitle = [dictionary objectForKey:@"Title"];
//Push the new table view on the stack
[self.navigationController pushViewController:rvController animated:YES];
rvController.tableDataSource = children;
}
}
最后,我调用了 prepare for segue 来寻找标记为 segue1 的 segue。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"segue1"])
{
DrillDownDetailController *dvController = [[segue destinationViewController] visibleViewController];
//DrillDownDetailController *dvController = [[DrillDownDetailController alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
[dvController setItemName:(NSString *)sender];
[self.navigationController pushViewController:dvController animated:YES];
}
}
我认为这会起作用,但由于某种原因,每当代码到达时[self performSegueWithIdentifier:@"segue1" sender:myString];
,它就会因错误而中断
*****终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因: '接收器()没有赛格瑞具有标识符'segue1'' *第一掷调用堆栈:(0x14b4022 0xeb4cd6 0xdf61b 0x3590 0xa85c5 0xa87fa 0x93d85d 0x1488936 0x14883d7 0x13eb790 0x13ead84 0x13eac9b 0x139d7d8 0x139d88a 0x17626 0x23ed 0x2355 0x1)终止调用抛出异常(lldb)
我不明白为什么它告诉我当它已经在故事板和代码中定义时它找不到 segue1。