1
Good evening, I have a function that is attached to a button, I would like to call it directly without the need of the button, what I do?
The function...
static func goToTutorialOrTo(market: Market, from viewController: UIViewController) {
BusinessesContainer.selectedMarket = market
AnswersHelper.sendAccessMarketTracker()
if UserDefaultManager.didSawTutorial() {
let rootMarketViewController = StoryBoard.rootMarketViewController()
viewController.present(rootMarketViewController, animated: false, completion: nil)
} else {
let tutorialViewController = StoryBoard.main().instantiateViewController(withIdentifier: "tutorial")
viewController.present(tutorialViewController, animated: true, completion: nil)
}
}
The function called by the button...
extension SupermercadosZonaViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
StoryBoard.goToTutorialOrTo(market: selectedMarketsToShowInTableView[indexPath.row], from: self)
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return StoryBoard.isIpad ? 175 : 110
}
}
My attempt to call her directly
First...
StoryBoard.goToTutorialOrTo(market: Market.init(json: <#T##JSON#>)!, from: self as! UIViewController)
Second...
SupermercadosZonaViewController()
Neither I have succeeded.
What error do you find when calling your function? Please share the log as well.
– Rici
when use second test>>>>>>>>>>>>>>>>>>>>>>>
 attempted;Fatal error: To read an unowned Reference but the Object was already deallocated2018-05-16 16:02:51.915443-0300 Mercadapp[5068:62259] Fatal error: Attempted to read an unowned Reference but the Object was already deallocated
– Crgd
The error says that you used an object that didn’t "manage" your own memory (
unowned reference
), I mean, I didn’t have a strong relationship (strong
) with the object in question. It seems that it has nothing to do with the shape you are presenting your screen, but rather with some object used in this routine. Tip: Search for that code block in your project for a capture list or any reference toUnmanaged
.– Rici