http://pixs.ru/showimage/Snimokekra_4555441_13580029.png

Guys, help transfer a dictionary (NSDictionary) from one storyboard to another.

The PlacesCollectionViewController class is responsible for the first view, the second MenuViewController is responsible for the second view, and the CustomTabBarController class is responsible for the tab controller (which is in between).

As I understand it, it is impossible to transfer data directly from PlacesCollectionViewController to MenuViewController.

Now I transfer from PlacesCollectionViewController (which is 1) to CustomTabBarController, and everything works, only then I do not have the knowledge to pull out this data for the class MenuViewController (which is 2).

Help, if not difficult.

I am writing to swift, but I will also analyze the code on ObjC.

The catch is that by specifying prepareForSeque (transition preparation) that the destination (destinationViewController) is MenuViewController (which is 2), I get no errors, I get a compiler crash and a transition to a line that my brain cannot interpret - 0x10bb415ed: movq% r14,% rax

  • You can transfer the data directly and present the controller modally, as an option, this is done in a couple of minutes and it will be very simple. But now you have an obvious problem with the design of the branch of the screens, there is a way out, but it will not be easy if you want the second screen to appear in the UITabBarController. - iFreeman
  • Alternatively, you can make the screen a member of UITabBarController, but hide the UITabBar for it, then there will be a separate screen effect, but you can easily show the desired data screen and all this is inside UITabBarController. - iFreeman
  • You are right, and this option has already been implemented, but the logic of the application itself is so lost and I don’t want to call it a crutch. On your first comment, please give me some code, quite a bit)) Just thinking at the moment - nil - bodpad

1 answer 1

For example:

class PlacesCollectionViewController : UICollectionViewController, UITabBarControllerDelegate { override func prepareForSegue(segue, sender: AnyObject!) { if let identifier = segue.identifier { switch identifier { case "GoTabController": if let tabVC = segue.destinationViewController as? UITabBarController { tabVC.delegate = self } default: println("unhandled segue \(identifier)") } } } func tabBarController(tabBarController: UITabBarController!, didSelectViewController viewController: UIViewController!) { if let indexPath = collectionView.indexPathForSelectedRow() { if let nav = viewController as? UINavigationController { if let vc = nav.viewControllers.first as? MenuViewController { vc.data = items[indexPath.item] } } } } } 

Not sure whether the PlacesCollectionViewController should continue to be a delegate, and perhaps no, you can reassign it, for example, or underestimate it.

You can pass data to the CustomTabBarController in prepareForSegue, make CustomTabBarController delegates of yourself and, using the same delegate method that I described above, implement the transfer of the dictionary to the desired MenuViewController.

  • iFreeman let me ask one more question, maybe the answer to it will solve my problem. Suppose I passed the dictionary in TabBarController and in the viewDidLoad method of this class I can operate with this data and now TabBarController shows my MenuViewController (which is 2) with the view of the first tab. to the TabBarController data that just received it. - bodpad
  • It turns out that if I cannot transfer data directly to MenuViewController (which is 2) in prepareForSegue, then I can accurately transfer the data to the TabBarController and already (firstly) in the first controller of the first tabBar view, get this data. - bodpad
  • @bodpad, MenuViewController should not get anything from nowhere, you should put data into it, I described the way out, using the didSelectViewController delegate method you get a UIViewController, which now will be shown in UITabBarController, respectively, check it (by index or by membership to the class, as I described in the example) and pass there the data you want. After that, in the viewDidLoad MenuViewController your dictionary is already available to you and you can operate it. - iFreeman