ermalkaleci / CarbonKit

CarbonKit - iOS Components (Obj-C & Swift)
MIT License
682 stars 164 forks source link

Crash when swiping away from a UITableViewController with an active UISearchController #63

Closed gca3020 closed 8 years ago

gca3020 commented 8 years ago

As stated in the title. I have a single subclass of UITableViewController that I am instantiating multiple times (holding different subsets of data in each). I have a UISearchController initialized in the viewController, and the tableView.tableHeaderView is set as searchController.searchBar.

` let searchController = UISearchController(searchResultsController: nil)

override func viewDidLoad() {
    super.viewDidLoad()

    // Set up the search bar
    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false
    searchController.hidesNavigationBarDuringPresentation = false

    definesPresentationContext = true
    tableView.tableHeaderView = searchController.searchBar
}

`

If I click into the search field and start searching, and then switch view controllers by swiping or clicking on a new one, I get a crash.

From the debugging output, it looks like there is an exception thrown: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unexpected subviews'

ermalkaleci commented 8 years ago

hey @gca3020 I am not sure what you are trying to do. ezgif-4224294470

gca3020 commented 8 years ago

That's strange. That's very similar to what I'm doing, except mine is crashing. Only when I have the search bar active.

Other minor differences are that my table currently has no items in it (empty array), and that I'm moving tabs between two instances of the same TableVC, both with a search bar at the top.

gca3020 commented 8 years ago

Some additional details on the exception: 2016-02-01 06:43:17.183 MyApp[8384:2378159] *** Assertion failure in -[_UIQueuingScrollView _setWrappedViewAtIndex:withView:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.30.14/_UIQueuingScrollView.m:332 2016-02-01 06:43:17.191 MyApp[8384:2378159] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unexpected subviews' *** First throw call stack:

A Google search shows this, which looks similar: http://stackoverflow.com/questions/24675000/uipageviewcontroller-nsinternalinconsistencyexception

galip91 commented 8 years ago

I am having the exact same issue with an UISearchBar. when it's in focus or firstResponder and I click on a different tab it crashes. my code is the same as @gca3020's

galip91 commented 8 years ago

any updates on this issue?

ermalkaleci commented 8 years ago

This crash is cause by UISearchController, so you should consider dismissing the search before changing tab

anuranBarman commented 5 years ago

I had the similar issue. If you are hiding the search bar on tab switch make sure you are hiding it in the delegate function

func carbonTabSwipeNavigation(_ carbonTabSwipeNavigation: CarbonTabSwipeNavigation, willMoveAt index: UInt)

This will solve the problem I guess. I was playing with the constraint of the search bar. so I put the code in the above function and it worked well.