0

I am referring project from GitHub.

I am trying to modify it according to my requirement, but I am not getting and not able to understand that what code I have to write in didSelectRowAtIndexPath method.

Here is image

What I want is that after clicking tableView row it can level 0 or level 1 (here level 0 means - row has no sub child and level 1 means row has subview/child rows )

When I click on any tableView row either level 0 or level 1, it has to navigate to next viewController.

In this example, row number 2 and 3 are expandable i.e it contains level 1 rows, row 0, 1, 4 and 5 are level 1 rows they don't expand.

Here is project link (updated project link)

***** Added Code ****

the code I written in AppDelegate class,

- (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;

}

And in LoginViewController class, I have written code

- (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];
}
Priyanka Patil
  • 318
  • 1
  • 9
  • 1
    Instead of posting a link to a project, [edit] your question to include relevant code and clearly explain what you need help with. – rmaddy May 30 '18 at 14:48

3 Answers3

2

Try this. ProductVC is your class where you want to push

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];

So like this you can move to any class, in didselectrowatindexpath just put validation for which row you want which class to push.

Kalpesh Panchasara
  • 1,730
  • 2
  • 15
  • 27
  • Already I did this. It is not working. In this class some code is different. – Priyanka Patil May 30 '18 at 13:07
  • See when you tap on Products, Contacts and cabs etc then it will call didselectrowatindexpath and it will push to another class. Did you tried like this – Kalpesh Panchasara May 30 '18 at 13:43
  • - (void)ftFoldingTableView:(FTFoldingTableView *)ftTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [ftTableView deselectRowAtIndexPath:indexPath animated:YES]; kpclass * kp = [[kpclass alloc] init]; [self.navigationController pushViewController:kp animated:YES]; } – Kalpesh Panchasara May 30 '18 at 13:49
  • This is written in your code only in didselectrowatindexpath. kpclass is the class i had created where i navigated – Kalpesh Panchasara May 30 '18 at 13:50
  • you are referring the wrong project. I updated correct project URL, please check it once, that previous project has no issue. – Priyanka Patil May 30 '18 at 13:53
  • oh i see. i am updating my answer have a look and update for other class as well. – Kalpesh Panchasara May 30 '18 at 14:15
  • @SShekh: please post your relevant code in your question, do not link to a project somewhere else. If that link expires, this whole question becomes useless. – koen May 30 '18 at 15:50
  • @Kalpesh you are genius, excellent code. I am very happy with this solution. Thank you so much. – Priyanka Patil May 31 '18 at 04:36
  • @Kalpesh Can you please help me, I stuck in the certain issue. – Priyanka Patil Jun 01 '18 at 04:56
  • What I am trying to do is that I want to use login feature, when a user logins with write credentials then that time I am storing one value in NSUserDefaults. Suppose if you closed the app and try to open the app then in AppDelegate class it checks one condition that NSUserDefaults contains that value if it is true then it will show direct home page, if not then it will login page. – Priyanka Patil Jun 01 '18 at 05:29
  • and after log in, in home page if you click on left navigation button then side-menu will open, when I clicked on Logout button then it will redirect to the login page, and it will remove that value from NSUserDefaults. So if you closed an app and try to open it again then it shows login page only not homepage because in AppDelegate class I am writing a code like if NSUserDefaults does not contain that value which was I am storing after successful login then it will show login page only. – Priyanka Patil Jun 01 '18 at 05:29
  • Yes this is the ideal flow and it should be like this only. What the issue you are facing here ??? – Kalpesh Panchasara Jun 01 '18 at 07:49
  • The side menu is not coming I mean it is not showing after clicking on sideMenu button in HomeViewComtroller – Priyanka Patil Jun 01 '18 at 08:52
  • I do not know what code I have to write in AppDelegate class, you added code in ExpandableTableViewController class was perfect , same thing like this I wants to add in AppDelegate class. I updated project and code, you can check it once. – Priyanka Patil Jun 01 '18 at 08:54
  • This is demo project, I am working on another project. same as demo project, I will share a video link please check if you have doubts. – Priyanka Patil Jun 01 '18 at 08:56
  • I have written a code in AppDelegate class so that if the user is logged in then it will open homepage instead of the login page and if the user is not logged in then it will show the Login page. Now the problem is that when running the code (user is already logged in) then suppose I clicked on left navigation button i.e sideMenu then that view controller is not showing. I do not know, why it is not coming, maybe some code is missing in AppDelegate class, I do not know what code I have to write, can you please help me. I updated project link, please check it once. – Priyanka Patil Jun 04 '18 at 07:52
1

Please write your parent navigation code in following method . For child view

- (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];
}

Write parent view navigation code following method

- (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");
}
0

Try this code working properly

-(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];

}