简体   繁体   English

如何在Expandable / Collapsable UITableView中从创建的tableview单元中筛选到详细视图

[英]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: 我发现有两种选择:

  • Create a segue 创建一个segue
  • Create a pushviewcontroller. 创建一个pushviewcontroller。

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: 您需要在此处检查几件事:

  1. Storyboard identifier for DetailViewController is set correctly. DetailViewController情节提要板标识符已正确设置。
  2. self.storyboard is initialized correctly. self.storyboard正确初始化。
  3. Root view have navigation Controller. 根视图有导航Controller。

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.

相关问题 从Tableview单元格到详细图像视图的Parse.com Segue - Parse.com Segue from Tableview Cell to Detail Image View NSMutableArray中的可扩展和可折叠UITableView部分 - Expandable & Collapsable UITableView sections from NSMutableArray iOS 5 Segue从uitableviewcell到另一个uitableview到详细视图(故事板) - iOS 5 Segue from uitableviewcell to another uitableview to detail view (storyboard) 如何在UITableView中转到下一个单元格(Detail View)? - How to go to the next cell (Detail View) in a UITableView? TableView和Detail视图单元格显示 - TableView and Detail view cell display iOS 8中的UITableView可扩展/可折叠部分,特定行部分不可扩展/可折叠 - UITableView expandable/collapsable sections in iOS 8,Particular row section is not expandable/collapsable 如何根据表视图单元格的详细文本标签,将segue设置为与表视图控制器不同的视图控制器? - How can I set a segue to a different view controller from a table view controller, based on the detail text label of the table view cell? 如何从表视图拉数组到详细信息视图? - How to pull Array from tableview to detail view? 从UITableView推送详细信息视图仅在单元格中的特定UIImage上? - Push Detail View from UITableView only on a specific UIImage in the cell? TableView和明细表 - TableView and Detail Segue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM