0

我指的是来自 GitHub 的项目。

我正在尝试根据我的要求对其进行修改,但我没有得到并且无法理解我必须在didSelectRowAtIndexPath方法中编写什么代码。

这是图像

我想要的是在单击 tableView 行后它可以是 0 级或 1 级(here level 0 means - row has no sub child and level 1 means row has subview/child rows )

当我单击级别 0 或级别 1 的任何 tableView 行时,它必须导航到下一个 viewController。

在此示例中,第 2 行和第 3 行是可扩展的,即它包含 1 级行,第 0、1、4 和 5 行是它们不扩展的第 1 级行。

这是项目链接(更新的项目链接)

***** 添加代码 ****

我在 AppDelegate 类中编写的代码,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.


   userDefaults=[NSUserDefaults standardUserDefaults];
mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];


if ([[NSUserDefaults standardUserDefaults] boolForKey:@"loginSuccess"]) {
      NSLog(@"Login Done!!!");

      HomeViewController *homeVC=[mainStoryboard instantiateViewControllerWithIdentifier:@"homeId"];

      SampleNavigationController *navigation = [[SampleNavigationController alloc] initWithRootViewController:homeVC];

    //SWRevealViewController * vc= [[SWRevealViewController alloc]init];

    //ExpandableTableViewController *sidemenu = (ExpandableTableViewController*)[mainStoryboard instantiateViewControllerWithIdentifier:@"sideMenu"];

      self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
      self.window.rootViewController = navigation;
      [self.window makeKeyAndVisible];

  }else
   {

      LoginViewController *loginVC=[mainStoryboard instantiateViewControllerWithIdentifier:@"LoginId"];

      self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
      self.window.rootViewController = loginVC;
      [self.window makeKeyAndVisible]; 
}

 return YES;

}

在 LoginViewController 类中,我编写了代码

- (IBAction)loginButtonMethod:(id)sender {
    [self->userdefaults setBool:YES forKey:@"loginSuccess"];

    InboxView *inboxVC=[self.storyboard  instantiateViewControllerWithIdentifier:@"id1"];
    [self.navigationController pushViewController:inboxVC animated:YES];
    [[self navigationController] setNavigationBarHidden:NO];
}
4

3 回答 3

2

尝试这个。ProductVC 是你想要推送的类

NSString * storyboardName = @"Main";
        NSString * viewControllerID = @"id3";
        UIStoryboard * storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
        ViewController3 * controller = (ViewController3 *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID];

        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController: controller];
        [navController setViewControllers: @[controller] animated: YES];
        [self.revealViewController setFrontViewController:navController];
        [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];

所以像这样你可以移动到任何类,在 didselectrowatindexpath 中只需验证你想要哪个类推送的行。

于 2018-05-30T12:52:46.973 回答
1

请按以下方法编写您的父导航代码。对于子视图

- (void)ftFoldingTableView:(FTFoldingTableView *)ftTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"indexPath--->%ld",(long)indexPath.row);
    //Write your  push next view controller code 
    [ftTableView deselectRowAtIndexPath:indexPath animated:YES];
}

编写父视图导航代码如下方法

- (void)ftFoldingTableView:(FTFoldingTableView *)ftTableView willChangeToSectionState:(FTFoldingSectionState)sectionState section:(NSInteger)section
{
    NSLog(@"section-->%ld",(long)section);
// Write push level 0 or parent view move next view controller code 

   // NSLog(@"section: %ld is about to %@", section, sectionState == FTFoldingSectionStateFold ? @"close" : @"open");
}
于 2018-05-30T13:06:43.023 回答
0

尝试此代码正常工作

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //check if the row at indexPath is a child of an expanded parent.
    //At a time only one parent would be in expanded state
    NSInteger indexSelected = indexPath.row;
    NSDictionary *dicSelected  =[self.itemsInTable objectAtIndex:indexSelected];
    /**
     Resolved the issue of top line separator dissapearing upon selecting a row (hackishly) by reloading the selected cell
     */
    @try {
        [self.menuTableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }
    @catch (NSException *exception) {
    }

    [tableView setSectionIndexBackgroundColor:[UIColor blackColor]];
    //
    //Collapse any other expanded cell by iterating through the table cells.
    //Don't collapse if the selected cell is a child of an expanded row.
    NSDictionary *dicCellToCollapse  =[self.itemsInTable objectAtIndex:g_ExpandedCellIndex];
    NSInteger numRowsCollapsed = 0;
    NSInteger level = [[dicSelected valueForKey:@"level"] integerValue];

    if(level==0 && [dicCellToCollapse valueForKey:@"SubItems"] && (g_ExpandedCellIndex != indexPath.row))
    {
        NSArray *arr=[dicCellToCollapse valueForKey:@"SubItems"];
        BOOL isTableExpanded=NO;

        for(NSDictionary *subitems in arr )
        {
            NSInteger index=[self.itemsInTable indexOfObjectIdenticalTo:subitems];
            isTableExpanded=(index>0 && index!=NSIntegerMax);
            if(isTableExpanded) break;
        }
        //
        //Collapse the parent cell if its expanded
        if(isTableExpanded)
        {
            [self CollapseRows:arr];
            numRowsCollapsed = [arr count]-1;
        }
    }

    //
    //go about the task of expanding the cell if it has subitems
    NSDictionary *dic;
    if (g_ExpandedCellIndex < indexPath.row && numRowsCollapsed)
    {
        dic = [self.itemsInTable objectAtIndex:indexPath.row-numRowsCollapsed-1];
    }
    else
    {
        dic = [self.itemsInTable objectAtIndex:indexPath.row];

    }



    //
    //Check if the selected cell has SubItems i.e its a Parent cell
    if([dic valueForKey:@"SubItems"])
    {
        arr=[dic valueForKey:@"SubItems"];
        BOOL isTableExpanded=NO;

        for(NSDictionary *subitems in arr )
        {
            NSInteger index=[self.itemsInTable indexOfObjectIdenticalTo:subitems];
            isTableExpanded=(index>0 && index!=NSIntegerMax);
            if(isTableExpanded) break;
        }
        //
        //Collapse the parent cell if its expanded
        if(isTableExpanded)
        {
            [self CollapseRows:arr];
        }
        //
        //Else expand the cell to show SubItems
        else
        {
//                    ViewController3 * vc = [self.storyboard instantiateViewControllerWithIdentifier:@"id3"];
//                    [self.navigationController pushViewController:vc animated:YES];
            //
            //store the location of the cell that is expanded
            NSUInteger rowIndex;
            if (g_ExpandedCellIndex < indexPath.row && numRowsCollapsed)
            {
                rowIndex = indexPath.row-numRowsCollapsed;//zero based index
                g_ExpandedCellIndex = indexPath.row-numRowsCollapsed-1;//zero based index
            }
            else
            {
                rowIndex = indexPath.row+1;
                g_ExpandedCellIndex = indexPath.row;
            }
            //
            //Insert the SubItems

            NSMutableArray *arrCells=[NSMutableArray array];
            for(NSDictionary *dInner in arr )
            {
                [arrCells addObject:[NSIndexPath indexPathForRow:rowIndex inSection:0]];
                [self.itemsInTable insertObject:dInner atIndex:rowIndex++];

                ViewController3 * vc = [self.storyboard instantiateViewControllerWithIdentifier:@"id3"];
                [self.navigationController pushViewController:vc animated:YES];
            }
            [self.menuTableView insertRowsAtIndexPaths:arrCells withRowAnimation:UITableViewRowAnimationTop];


        }
    }
    //Else a subItem has been clicked. We need to push the relevant view into segue
    else
    {
          NSString* strId =[dic valueForKey:@"id"];
          NSDictionary *dict = arr[0];
          NSString *id1=[dict objectForKey:@"id"];

          NSLog(@"%@",strId);
          NSLog(@"%@",id1);

          if([id1 isEqualToString:@"sme_marketwatch"])
          {
                      ViewController3 * vc = [self.storyboard instantiateViewControllerWithIdentifier:@"id3"];
                      [self.navigationController pushViewController:vc animated:YES];
          }

        ViewController3 * vc = [self.storyboard instantiateViewControllerWithIdentifier:@"id3"];
        [self.navigationController pushViewController:vc animated:YES];
//
//        ViewController1 * vc = [self.storyboard instantiateViewControllerWithIdentifier:@"id1"];
//        [self.navigationController pushViewController:vc animated:YES];


//          NSString* strId =[dic valueForKey:@"id"];
//          NSLog(@"Id is %@",strId);
//
//         if([strId isEqualToString:@"getquote"]) //getquote
//         {
//             ViewController3 * vc = [self.storyboard instantiateViewControllerWithIdentifier:@"id3"];
//             [self.navigationController pushViewController:vc animated:YES];
//         }



    }
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ViewController3 *newView = [storyboard instantiateViewControllerWithIdentifier:@"id3"];
    [self presentViewController:newView animated:YES completion:nil];




//    ViewController3 * vc = [self.storyboard instantiateViewControllerWithIdentifier:@"id3"];
//      [self.navigationController pushViewController:vc animated:YES];

}
于 2018-05-31T05:33:58.743 回答