1

I have an iOS application, built to support iOS5.1, and I was customizing the cancel button inside search bars.

The code I'm using and that works until iOS6.1 is the following:

id barButtonAppearanceInSearchBar =
    [UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil];
[barButtonAppearanceInSearchBar setTitle:
    [self localizedStringValueFor:@"Cancel"]];

Somehow the second line will cause a bad access exception, the barButtonAppearanceInSearchBar seems to be deallocated when I try to set the value for the button's text.

localizedStringForValue is a custom method that will return a String with the translation for the provided key or the key itself if not translation exists.

Now when I run the app on iOS7' simulator the app always crashes. Been trying to figure out what I'm doing wrong but no luck so far.

4

1 回答 1

1

setTitle不是支持UIAppearanceContainer方法。仅UI_APPEARANCE_SELECTOR支持标记为的属性。

您必须在创建时手动设置标题UISearchBar

于 2013-09-23T19:38:58.847 回答