UISearchBar自定义代码在iOS7中崩溃,适用于iOS6 [英] UISearchBar customization code crashes in iOS7, works on iOS6

查看:97
本文介绍了UISearchBar自定义代码在iOS7中崩溃,适用于iOS6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS应用程序,专为支持iOS5.1而设计,我在搜索栏中自定义取消按钮。

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

我正在使用的代码和那个直到iOS6.1如下:

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"]];

不知何故第二行会导致错误的访问异常, barButtonAppearanceInSearchBar 似乎被解除分配。

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 是一个自定义方法,如果不存在转换,将返回带有所提供密钥或密钥本身的转换的String。

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.

现在,当我在iOS7'模拟器上运行应用程序时该应用程序总是崩溃。一直试图找出我做错了但到目前为止没有运气。

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.

推荐答案

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

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

You will have to set the title manually when you create the UISearchBar.

这篇关于UISearchBar自定义代码在iOS7中崩溃,适用于iOS6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆