Creating manual segue correctly through storyboard and xcode

后端 未结 2 944
生来不讨喜
生来不讨喜 2020-12-15 06:14

I\'m quite new to xcode, and I am trying to develop a sample app that is basically an embedded tableview which has many levels. I have a plist which stores the cells of each

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-15 07:00

    THE MAIN ISSUE IS HERE, you were creating a blank DrillDownViewController, not reusing the one from storyboards, see comments in code below

        -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
        {
            if([[segue identifier] isEqualToString:@"segue1"])
            {
                 [segue.destinationViewController setItemName:(NSString*)sender];
            }
        }
    
        - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
        {
            //Check the dictionary to see what cell was clicked
           NSDictionary *dict = [self.tableDataSource objectAtIndex:indexPath.row];
    NSString *titleName = [dict objectForKey:@"Title"];
    NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
    
    NSArray *children = [dictionary objectForKey:@"Children"];
    
    if([children count] == 0)
    {
        [self performSegueWithIdentifier:@"segue1" sender:titleName];
    
    }
            else{
        //Prepare to tableview.
    
        //THE MAIN ISSUE IS HERE, you were creating a blank DrillDownViewController, not reusing the one from storyboards so it did not have a segue at all defined. instead do this:
        UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                      bundle:nil];
        DrillDownViewController *rvController = [sb instantiateViewControllerWithIdentifier:@"DDVC"];       
        //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;
    
    }
    
    
        }
    

提交回复
热议问题