Search code examples
iosobjective-cxcodexcode7.2

How to programmatically move to tableViewController or viewController based on condition


I have a root view controller called A and a table view controller called B. And when the user selects a row in B it opens another ViewController. What I am trying to say is that when there is only one row is present in the tableview it should be open directly open in that ViewController. As data is coming in JSON format.

screenshot of app so far


Solution

  • if(Option)
        //NSLog(@"%@",Option);
        {
            if (Option.count==1)
            {
                NSDictionary *dict=(NSDictionary*)Option[0];
                NSString *action=[dict valueForKey:@"action"];
            if([action isEqualToString:@"m-deals-json"])
                {
                    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
                                                                             bundle: nil];
                    UINavigationController *n=[mainStoryboard instantiateViewControllerWithIdentifier:@"DealsNavigation"];
                    DealsViewController *v=[mainStoryboard instantiateViewControllerWithIdentifier:@"DealsViewController"];
                    v.dict=dict;
                    self.window.rootViewController = n;
                    [self.window makeKeyAndVisible];
                }
            }
            else
            {
                UINavigationController *n=[mainStoryboard instantiateViewControllerWithIdentifier:@"NavigationController"];
                OffersViewController *v=[mainStoryboard instantiateViewControllerWithIdentifier:@"OffersViewController"];
                self.window.rootViewController = n;
                [self.window makeKeyAndVisible];
            }
        }