0

I have a tab bar application. My requirement is I select the 'scan' tab to scan the qr code and navigate/jump immediatley to another 'list' tab. Both 'scan' and 'list' tab are there in the viewControllers array in didFinishLaunchingWithOptions After referring this link, i don't think i need to set the delegate as both the tabs are already present in the hierarchy.

I get this warning in the following line

    if(x)
    {
    listViewCntrl = [[ListViewController alloc] initWithNibName:@"ListViewController" bundle:nil];
    listViewCntrl.getFlag = YES;
    [self presentViewController:listViewCntrl animated:YES completion:Nil]; // I get the warning here
    }

If I comment out the above code and add

[self.tabBarController setSelectedIndex:1];

then I would not be able to get the subView of the listViewController (set flag to show the subview) which i need to display inside the list tab after scanning.

App crashes if I add

[self.tabBarController setSelectedViewController:listViewCntrl];

So how do I display the listView's subview after scanning?

Community
  • 1
  • 1
Deepak Thakur
  • 3,453
  • 2
  • 37
  • 65

2 Answers2

0
ListViewController *listController = (ListViewController*)[self.tabController viewControllers][1];
listController.getFlag = 1;
[self.tabBarController setSelectedIndex:1];

The problem is that you're creating an entirely new ListViewController. You say you already have one in the tab controller - you don't need a new one.

You can't use your 3rd option because, again, the two ListViewController's are different objects (they may be of the same class, but they point to a different address).

Harry
  • 3,076
  • 4
  • 28
  • 44
  • I get this error for flag [UINavigationController setGetFlag:]: unrecognized selector sent to instance and it does not navigate to index:1 if I comment out the flag line – Deepak Thakur Dec 02 '13 at 11:46
  • @OptimusPrime Right, sure, so you have a UINavigationController for that particular tab, then I guess ListViewController is somewhere in the navigation stack. I know next to nothing about your application so I can't really give you a definitive answer here, but try out the `viewControllers` or `topViewController` properties on UINavigationController. – Harry Dec 02 '13 at 11:57
0

You can try this if you use storyboard:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
ViewController * destViewController = [storyboard instantiateViewControllerWithIdentifier:@"ViewControllerIdentifier"];
[self.navigationController pushViewController:destViewController animated:YES];

You have to set an identifier for your controller in your storyboard.

hoya21
  • 893
  • 7
  • 24
  • i did not use storyboard in my project. Also if i use [self.navigationController ...] it will navigate within the same tab. I need to change the tab index as well. Thats my requirement. – Deepak Thakur Dec 02 '13 at 13:29