I am passing data from a collection view cell when I push to a tab bar controller.
I have a Navigation Controller which I push a segue to a tabbarcontroller. So the TabBarController is in a navigation controller.
The data pass works excellent with this code which is in my prepare to segue.
let indexPaths = self.collectionView!.indexPathsForSelectedItems()!
let indexPath = indexPaths[0] as NSIndexPath
let row = indexPath.row
let tabar = segue.destinationViewController as! ResultsDetailViewController
tabar.photoData = photoDataStore[row]
I subclass the TabBarController with a variable of photoData. So all child view controllers work excellent.
But what I am trying to do is if photo2 is nil, then remove the 3rd view controller of the tabbarcontroller. I got this code from another post. Issue is self.tabbarcontroller is returning nil. Can't figure out why?
if let tabBarController = self.tabBarController {
let indexToRemove = 2
if indexToRemove < tabBarController.viewControllers?.count {
var viewControllers = tabBarController.viewControllers
viewControllers?.removeAtIndex(indexToRemove)
tabBarController.viewControllers = viewControllers
}
}
As the tabbarcontroller was developed through storyboard I did not set it up in appdelegate.
In the end I want the number of tabbar buttons and hence the number of view controllers to be dynamic.
Thanks