Skip to content

Adding a tab via activateTab when viewControllers is empty causes crash. #1

Description

@iosdevzone

If the view controllers array is empty and activateTab is called to add a tab an assertion failure will cause the program to crash

2018-04-02 15:18:46.925062-0700 TabView Sample[331:36129] 
*** Assertion failure in -[TabView.TabViewTabCollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:],
 /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3698.52.10/UICollectionView.m:6031
2018-04-02 15:18:46.926864-0700 TabView Sample[331:36129] 
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'Invalid update: invalid number of items in section 0.  
The number of items contained in an existing section after the update (1) must be equal to 
the number of items contained in that section before the update (1), plus or minus the number 
of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the 
number of items moved into or out of that section (0 moved in, 0 moved out).'

This behavior can be seen in the Sample project by making the following edit to ViewController.swift

        // Set the tabs in this tab view
//        self.viewControllers = [
//            Tab(title: "White", color: .white),
//            Tab(title: "Black", color: .black),
//            Tab(title: "Red", color: .red),
//            Tab(title: "Green", color: .green),
//            Tab(title: "Blue", color: .blue),
//            Tab(title: "A really long title", color: .blue)
//        ]
		
		self.activateTab(Tab(title: "Red", color: .red))

I haven't been able to quite figure out what is going on. If I do a PR will be forthcoming.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions