[英]how to segue to a detail view from created tableview cell in Expandable/Collapsable UITableView
I am kinda new in Xcode and now I am working on a Expandable/Collapsable UITableView. 我是Xcode的新手,现在正在开发可扩展/可折叠UITableView。 The basic idea is to create new sub dropdown cells when the first master cell is clicked and subcells can segue to a detail view.
基本思想是,当单击第一个主单元格并且子单元格可以缝到详细视图时,创建新的子下拉单元格。 But I hope to segue to a detail view from those new sub cells.
但是我希望从这些新的子单元中获取详细的视图。 I found there are two options:
我发现有两种选择:
I dragged a new view controller and defined its storyboard ID, and tried to programmatically create a segue to push the new detail view. 我拖动了一个新的视图控制器,并定义了其情节提要ID,并尝试以编程方式创建segue以推送新的详细信息视图。 but it is not working.
但它不起作用。 Could anyone help me?
有人可以帮我吗? Thanks.
谢谢。
//didSelectRowAtIndexPath // didSelectRowAtIndexPath方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//to change the button image when selecting a row.
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIButton *arrowBtn = (UIButton*)[cell viewWithTag:10];
NSDictionary *dic=[self.itemsinTable objectAtIndex:indexPath.row];
if([dic valueForKey:@"list"])
{
NSArray *listarray=[dic valueForKey:@"list"];
BOOL isTableExpanded=NO;
for(NSDictionary *subitems in listarray )
{
NSInteger index=[self.itemsinTable indexOfObjectIdenticalTo:subitems];
isTableExpanded=(index>0 && index!=NSIntegerMax);
if(isTableExpanded) break;
}
if(isTableExpanded)
{
[self CollapseRows:listarray];
[arrowBtn setImage:[UIImage imageNamed:@"down_arrow.png"] forState:UIControlStateNormal];
}
else
{
NSUInteger count=indexPath.row+1;
NSMutableArray *arrCells=[NSMutableArray array];
for(NSDictionary *dInner in listarray )
{
[arrCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
[self.itemsinTable insertObject:dInner atIndex:count++];
}
[self.expandingtableView insertRowsAtIndexPaths:arrCells withRowAnimation:UITableViewRowAnimationTop];
[arrowBtn setImage:[UIImage imageNamed:@"up_arrow.png"] forState:UIControlStateNormal];
//This segue is not working...
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"detailvcontroller"];
[self.navigationController pushViewController:controller animated:YES];}}}
detailvcontroller *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"detailvcontroller"];
[self.navigationController pushViewController:controller animated:YES];
You need to check couple of things here: 您需要在此处检查几件事:
DetailViewController
is set correctly. DetailViewController
情节提要板标识符已正确设置。 self.storyboard
is initialized correctly. self.storyboard
正确初始化。 I just added below storyboard intialization code. 我只是在情节提要初始化代码下面添加了代码。 Please ensure your
self.storyboard
is being set this way: 请确保以这种方式设置您的
self.storyboard
:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
DetailViewController *viewController = (DetailViewController *)[storyboard instantiateViewControllerWithIdentifier:@"detailvcontroller"];
[self.navigationController pushViewController:controller animated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.