The code below performs a series of rest calls to a server, to display or not view controllers inside a controller bar tab, the fact is that when it has to display the view controller (TipologiaPermesso: "magazzino") it goes into crash, what is it due? and how can I solve this, all calls are asynchronous to a node.js server that responds with a json
Code:
import UIKit
class TabBarViewController: UITabBarController {
var u: User = User()
/* Genero L'UITabBarController creando le ViewController ed inserendole in un array! */
override func viewDidLoad() {
super.viewDidLoad()
var tabFrame = self.tabBar.frame
tabFrame.size.height = 60
self.tabBar.frame = tabFrame
hideKeyboardWhenTappedAround()
//Controllo permesso accesso cantieri
let u = User()
let MarcaTempoView = MarcaTempoViewController()
MarcaTempoView.tabBarItem = UITabBarItem(title: "Marca Tempo", image: UIImage(named: "clock.png")?.scaleImage(toSize: CGSize(width: 10, height: 10)), tag: 0)
let CantieriView = CantieriViewController()
CantieriView.tabBarItem = UITabBarItem(title: "Cantieri", image: UIImage(named: "home.png")?.scaleImage(toSize: CGSize(width: 10, height: 10)), tag: 1)
let ArticoliView = RicercaArticoliViewController()
ArticoliView.tabBarItem = UITabBarItem(title: "Articoli", image: UIImage(named: "articoli.png")?.scaleImage(toSize: CGSize(width: 10, height: 10)), tag: 2)
let UserView = UserViewController()
UserView.tabBarItem = UITabBarItem(title: "Utente", image: UIImage(named: "user.png")?.scaleImage(toSize: CGSize(width: 10, height: 10)), tag: 3)
let ClienteView = ClienteViewController()
ClienteView.tabBarItem = UITabBarItem(title: "Clienti", image: UIImage(named: "risorse_umane.png")?.scaleImage(toSize: CGSize(width: 10, height: 10)), tag: 4)
let MagazzinoView = RicercaArticoliViewController()
MagazzinoView.Stato = "Magazzino"
MagazzinoView.u = u
MagazzinoView.tabBarItem = UITabBarItem(title: "Magazzino", image: UIImage(named: "warehouse.png")?.scaleImage(toSize: CGSize(width: 10, height: 10)), tag: 5)
var viewControllerList = [MarcaTempoView, CantieriView, ArticoliView, UserView, ClienteView, MagazzinoView]
DispatchQueue.main.async {
//Controllo permesso accesso marcatempo
u.VerificaPermesso(TipologiaPermesso: "marcatempo", completion: { result in
DispatchQueue.main.async {
if(result == "false") {
viewControllerList.remove(at: 0)
self.viewControllers = viewControllerList
}
}
});
//Controllo permesso accesso Clienti
u.VerificaPermesso(TipologiaPermesso: "clienti", completion: { result in
DispatchQueue.main.async {
if(result == "false") {
viewControllerList.remove(at: 4)
self.viewControllers = viewControllerList
}
}
});
//Controllo permesso accesso Articoli
u.VerificaPermesso(TipologiaPermesso: "articoli", completion: { result in
DispatchQueue.main.async {
if(result == "false") {
viewControllerList.remove(at: 2)
self.viewControllers = viewControllerList
}
}
});
//Controllo permesso accesso Magazzino
u.VerificaPermesso(TipologiaPermesso: "magazzino", completion: { result in
DispatchQueue.main.async {
if(result == "false") {
viewControllerList.remove(at: 5)
self.viewControllers = viewControllerList
}
}
});
u.VerificaPermesso(TipologiaPermesso: "cantieri", completion: { result in
DispatchQueue.main.async {
if(result == "false") {
viewControllerList.remove(at: 1)
self.viewControllers = viewControllerList
}
}
});
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}