Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
iosdevzone opened this issue Apr 2, 2018 · 5 comments

Comments

@iosdevzone
Copy link

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.

@iosdevzone iosdevzone changed the title Add tab via activateTab when viewControllers is empty causes crash. Adding a tab via activateTab when viewControllers is empty causes crash. Apr 2, 2018
@iosdevzone
Copy link
Author

A little more information on this.

As long as the viewControllers array is assigned before the first call to activateTab the problem does not occur. So it must be some side-effect of the set block on viewControllers.

    // No crash
    self.viewControllers = [ ]		
    self.activateTab(Tab(title: "Red", color: .red))

iosdevzone pushed a commit to iosdevzone/TabView that referenced this issue Apr 2, 2018
@iosdevzone
Copy link
Author

The above commit (46bf391) appears to solve the problem for me.

@ian-mcdowell
Copy link
Owner

Thanks for looking into this, @iosdevzone. I'll take a look into this as well. If you have a working solution, feel free to open a PR.

@ian-mcdowell
Copy link
Owner

I've opened PR #2, which fixes this issue locally for me. Can you confirm?

@iosdevzone
Copy link
Author

iosdevzone commented Apr 4, 2018

Thanks for the speedy response. Yes, #2 solves the problem and probably does less unnecessary work than my solution.

Oh and also, thanks for this great framework. It's saved me a ton of time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants