Minitour / AZTabBarController

A custom tab bar controller for iOS written in Swift 4.2
MIT License
348 stars 65 forks source link

.set(selectedIndex:, animated:) crash #9

Closed daerimin closed 7 years ago

daerimin commented 7 years ago

Hi again,

Sorry to bother you with another issue but I'm getting a crash when I try to manually set the selected index:

let tabController = AZTabBarController.insert(into: self, withTabIcons: icons)

tabController.set(viewController: UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "vc1"), atIndex: 0)
tabController.set(viewController: UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "vc2"), atIndex: 1)
tabController.set(viewController: UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "vc3"), atIndex: 2)
tabController.set(viewController: UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "vc4"), atIndex: 3)
tabController.set(viewController: UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "vc5"), atIndex: 4)
tabController.set(viewController: UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "vc6"), atIndex: 5)

tabController.selectedColor = self.gk.rgbToUIColor(hex: "cf5731")
tabController.selectionIndicatorColor = UIColor.white
tabController.buttonsBackgroundColor = UIColor.white

--> tabController.set(selectedIndex: 2, animated: false)

when this runs, it crashes here:

private func moveToController(at index:Int,animated:Bool){
     if let controller = controllers[index] {
          // Deselect all the buttons excepting the selected one.
          for i in 0 ..< self.tabIcons.count{
-->            let button:UIButton = self.buttons[i] as! UIButton

I set a breakpoint, and it looks like self.buttons is nil.

Minitour commented 7 years ago

@daerimin Thanks for bringing this to my attention, I am working on a fix.

Minitour commented 7 years ago

@daerimin Fixed with the release of 1.1.1

daerimin commented 7 years ago

That's got it! Thank you so much! :)

Minitour commented 7 years ago

Thank you for contributing!