1

So I have a ViewController that navigates to another one when didSelectRowAt is called. I navigate to the new view controller as such:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let accountInsightsViewController:AccountInsightsViewController = AccountInsightsViewController(nibName: "AccountInsightsViewController", bundle: nil)
    accountInsightsViewController.accountDetailsObjectFromSourceController = self.accountDetailsObjectFromSourceController
   accountInsightsViewController.accountDetailsObjectFromSourceController["accountId"] = self.accountDetailsObjectFromSourceController["accountId"]
    if let navigator = navigationController {
        navigator.pushViewController(accountInsightsViewController, animated: true)
    }

}

However, in this new view controller's viewDidLoad() function, the attribute accountDetailsObjectFromSourceController becomes an empty dictionary again. When I debug, I can clearly see that when I set this attribute dictionary to dictionary of the same structure, it happens to properly set the value of the dictionary to the dictionary with 3 key/value pairs. However, when the navigationController pushes this VC, it crashes because this dictionary has 0 key/value pairs inside the new VC's viewDidLoad()

Would someone be able to tell me why the value is being set, but when it navigates to this VC, the dictionary is then empty? The view controller comes in the form of its own XIB file and VC Swift file. Clearly I am doing the right thing, and it hits the viewDidLoad(), but why won't it take the value that I set right before pushViewController?

btrballin
  • 1,420
  • 3
  • 25
  • 41
  • Maybe - by mistake - you also have configured a segue from the cell to the insights view controller, which then will also be pushed on the navigation stack, causing the problems. Please check the segues or check if really only one insights view controller exists (and this is the one you created in `didSelectRowAt`. – Andreas Oetjen Jan 22 '20 at 08:22
  • There are no segues. My code clearly shows that it’s being navigated by a navigation controller – btrballin Jan 23 '20 at 21:56

1 Answers1

0

Interesting issue. It was solved by first hardcoding the dictionary values. In this case, there was another underlying issue raised that prevented the VC from appearing. This was the issue's solution: Loaded nib but the 'view' outlet was not set

Once the VC loaded with the hardcoded values, it was not "resetting" the dictionary that was being passed in before the pushViewController. The issue stemmed from attempting to migrate a VC UI away from the storyboard into a separate XIB

btrballin
  • 1,420
  • 3
  • 25
  • 41