我对xcode很陌生,我正在尝试开发一个示例应用程序,它基本上是一个嵌入式tableview,它有很多级别。我有一个plist存储每个tableview的单元格。如果细胞没有孩子,那么一旦细胞被按下,我希望能够进入一个详细的视图。最终,我希望能够根据数据类型转到不同的详细视图。为此,我创建了故事板的详细视图,将我的视图控制器拖到我的详细视图中,以创建手动“推”渐变,并将其标记为“segue1”。通过故事板和xcode正确创建手动segue
编辑:源代码here
接下来,我填写了我认为是必要的功能,这个工作,这是调用[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;
}
}
最后,我打电话给准备for segue寻找segue标签segue1。
-(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。
我可能会在这里完全关闭,因为我没有使用segues,但尝试声明'DrillDownDetailController * dvController'作为实例变量,然后在'prepareForSegue'中设置您需要在VC上的任何属性。不要把风险投资推到海军控制员身上,然后再进行调整。 – mkral
@mkral你能否详细说明“不要把VC推到海军控制员的准备中,然后再进行调整”?因此,删除pushViewController行并将该行放入新的performSegue函数中? – foboi1122
我会添加一个格式化的答案。如果它不起作用希望别人能来 – mkral