在iOS 4.2中更改UISwitch文本 [英] Changing of UISwitch text in iOS 4.2

查看:68
本文介绍了在iOS 4.2中更改UISwitch文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改UISwitch中的文本。来自网站的示例(更改UISwitch上的文本)工作正常,但当我将我的xcode升级到3.2.5和iOS 4.2时,在调用函数来更改文本时应用程序崩溃。我在网站上使用以下示例。

I am trying to change the text in UISwitch. The sample from the website ( Changing the text on a UISwitch ) works fine but when I upgrade my xcode to 3.2.5 and iOS 4.2, the application crash when the functions is being called to change the text. I am using the following example from the website.

例如。

((UILabel *)[[[[[[_agreeAgb subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:0]).text = @"Foo";
((UILabel *)[[[[[[_agreeAgb subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:1]).text = @"Bar";

抛出的异常是因为遇到了null对象。

The exception thrown is because null object is encountered.

谢谢。

推荐答案

不要这样做。操纵框架控件的私有视图层次结构绝对不受支持,并且可能导致与OS更新不兼容。特别是因为您的代码绝对没有验证层次结构,所以如果子视图的数量或类型与您期望的不匹配,您很容易崩溃。

Don't do this. Manipulating the private view hierarchy of framework controls is absolutely unsupported, and can cause incompatibility with OS updates. Especially as your code does absolutely no verification of the hierarchy, so you can very easily crash if the number or type of subviews doesn't match what you were expecting.

这篇关于在iOS 4.2中更改UISwitch文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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