inloop / Styles

Styling iOS apps made easy
MIT License
18 stars 2 forks source link

Problem caused by UITextField's method swizzling, manifested in UISearchController's searchBar #82

Closed VilemKurz closed 6 years ago

VilemKurz commented 6 years ago
  1. use UISearchController and Styles in a project. Styles do not need to be applied to UISearchController.
  2. search for something
  3. tap on any result to go into detailViewController
  4. tap back on detailViewController

The bug: on return, UISearchController unexpectedly calls updateSearchResults (which might trigger a network request). Expected behaviour: on return nothing happens, user sees what he left, no search results update is triggered

The bug source (stack trace tells): thanks to method swizzling in Styles (swizzle_becomeFirstResponder on UITextField category), a new attributed search string is set which triggers UISearchController's delegate call - even if user did not change the search string - only because UISearchController is focused again. UIKit's implementation calls becomeFirstResponder on searchBar's textfield in order to restore keyboard when the scene with UISearchController is going to be showed back.

Initially I thought, not a big deal, I will just remove Styles styling from UISearchController's search bar and the problem is gone. But NO, I double checked that Styles are not applied to any app's UISearchControllers.

VilemKurz commented 6 years ago

Closing, as this is not a problem of Styles lib. My wrong assumption. It is a feature of UISearchController.