UISearchBar的set_cancelButtonText:禁止使用ivar [英] UISearchBar's set_cancelButtonText: ivar is prohibited
问题描述
以前在iOS 12中允许使用相同的代码,但是现在当我尝试在iOS 13上运行相同的代码时,它崩溃并给我同样的错误:
Previously in iOS 12 the same code was allowed, but now when i try to run the same code on iOS 13 it crashes giving me the same error:
由于未捕获的异常"NSGenericException"而终止应用程序,原因:访问UISearchBar的set_cancelButtonText:ivar是禁止.这是一个应用程序错误'
Terminating app due to uncaught exception 'NSGenericException', reason: 'Access to UISearchBar's set_cancelButtonText: ivar is prohibited. This is an application bug'
与以下代码行相关:
searchController.searchBar.setValue("Cancel".localized, forKey:"_cancelButtonText")
现在,我知道现在禁止访问setValue,但是如何克服此崩溃并更改取消"按钮的标题,因为搜索栏中不包含任何属性.
Now i know the access of setValue is now prohibited but how is it possible to overcome this crash and change the title of cancel button, since there is no property included in the searchbar.
推荐答案
您可以使用 UIAppearance
:
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).title = "Whatever"
这篇关于UISearchBar的set_cancelButtonText:禁止使用ivar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!