GocePetrovski / ScrollableSegmentedControl

Scrollable Segmented Control for when UISegmentedControl is not sufficient
MIT License
245 stars 74 forks source link

Index out of range when inserting segment #31

Closed AgungLaksana closed 5 years ago

AgungLaksana commented 5 years ago

I just recently update the pod from pod 1.3.0 to 1.4.0

here is the code I use to set up the segmented control


import ScrollableSegmentedControl

@IBOutlet weak var segmentedController: ScrollableSegmentedControl!

       segmentedController.segmentStyle = .textOnly

        segmentedController.insertSegment(withTitle: "asasasa", at: 0)
        segmentedController.insertSegment(withTitle: "Semua", at: 0)
        segmentedController.insertSegment(withTitle: "Kopi", at: 1)
        segmentedController.insertSegment(withTitle: "Air Dalam Kemasan", at: 2)
        segmentedController.insertSegment(withTitle: "Makanan Instan", at: 3)
        segmentedController.insertSegment(withTitle: "Susu", at: 4)
        segmentedController.insertSegment(withTitle: "Sabun Cuci Piring", at: 5)
        segmentedController.insertSegment(withTitle: "Bumbu Dapur", at: 6)

        segmentedController.underlineSelected = true

        segmentedController.addTarget(self, action: #selector(HomeVC.segmentSelected(sender:)), for: .valueChanged)

        // change some colors
        segmentedController.segmentContentColor = UIColor.darkGray
        segmentedController.selectedSegmentContentColor = UIColor.darkGray
        segmentedController.backgroundColor = UIColor.white
        segmentedController.tintColor = UIColor.black // underline color

        // default position
        segmentedController.selectedSegmentIndex = 0

        segmentedController.fixedSegmentWidth = false

but I dont know why the app crash in line: segmentedController.insertSegment(withTitle: "asasasa", at: 0)

with error message: Thread 1: Fatal error: Index out of range

it worked without problem in 1.3.0, but since I update in 1.4.0 it makes crash.

I use Xcode 10, Swift 4.2

AgungLaksana commented 5 years ago

Case closed:

here is what I do to solve this problem:

  1. update cocoapod : sudo gem install cocoapods
  2. totally remove the pod, remove in podfile and run pod install
  3. add again pod 1.4.0 and run pod install again in terminal