0

I am kinda new in Xcode and now I am working on a Expandable/Collapsable 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
  • Create a 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. but it is not working. Could anyone help me? Thanks.

//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];}}}
Blunderfest
  • 1,854
  • 1
  • 28
  • 46
Clark
  • 1
  • 2

2 Answers2

1
detailvcontroller *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"detailvcontroller"];

[self.navigationController pushViewController:controller animated:YES];
spenibus
  • 4,339
  • 11
  • 26
  • 35
0

You need to check couple of things here:

  1. Storyboard identifier for DetailViewController is set correctly.
  2. self.storyboard is initialized correctly.
  3. Root view have navigation Controller.

I just added below storyboard intialization code. Please ensure your self.storyboard is being set this way:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
DetailViewController *viewController = (DetailViewController *)[storyboard instantiateViewControllerWithIdentifier:@"detailvcontroller"];
[self.navigationController pushViewController:controller animated:YES];
Abhinav
  • 37,684
  • 43
  • 191
  • 309