관리 메뉴

꿀맛코딩

iOS 13 UISearchBar _cancelButtonText Error 본문

공부방/iOS

iOS 13 UISearchBar _cancelButtonText Error

soycrab 2019. 10. 16. 18:05

iOS 13 에서

uiSearchBar.setValue("cancel".localized, forKey: "_cancelButtonText"

부분에서

Terminating app due to uncaught exception 'NSGenericException', reason: 'Access to UISearchBar's set_cancelButtonText: ivar is prohibited. This is an application bug'

위와 같은 에러 코드가 뿜어져 나오면서 앱이 죽어버렸다.

 

다른 iPhone 들에서는 멀쩡하게 작동 하던 코드가 왜 작동이 

안될까 하며 찾아 보던때에 

우연히 힌트를 발견했다. 

https://stackoverflow.com/a/29232231/11852339

이사람의 글에서 보면 key 값이 

_ (언더바) 가 빠져 있다. 

그래서

uiSearchBar.setValue("cancel".localized, forKey: "cancelButtonText")  와 

추가적으로 

uiSearchBar.setShowsCancelButton(true, animated: true)

Cancel Button 의 사용을 명시적으로 표기 해줬다.

 

이제 iPhone 11에서도 정상적으로 Cancel Button 이 동작한다. 

반응형
Comments