Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing of UISwitch text in 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.

eg.

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

The exception thrown is because null object is encountered.

Thanks.

like image 573
user510951 Avatar asked Nov 30 '22 04:11

user510951


1 Answers

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.

like image 163
Lily Ballard Avatar answered Dec 09 '22 15:12

Lily Ballard