New iOS5 UISwitch Doesn't Look Disabled in UITableViewCell

I host UISwitch es in a UITableViewCell , and first I try to disable it:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ... self.switch = [[UISwitch alloc] init]; self.switch.enabled = NO; cell.accessoryView = self.switch; ... } 

In versions of iOS prior to iOS5, the (old) switch is disabled, and also turns off (dims) when the view is displayed.

In iOS5 (new), the switch is disabled in order, I can not turn it over, but at this point it does not look disabled. It has the same brightness as the activated switch.

If I turn it on and off again later in the code (NOT in the cellForRowAtIndexPath: , it looks disabled (darkened).

Am I doing something wrong or is it a bug in iOS5?

+6
source share
3 answers

For what it's worth, the initializer assigned by UISwitch is -initWithFrame: - have you tried using this?

+3
source

I ran into the same issue with iOS 5. You can use -initWithFrame to create the switch, and then you can add this switch as a subset of the contents of the cellView and (not an accesoryview and don't forget to count the subviews contentView, otherwise you can add a new uiswitch ) using the -addSubview: method.

+2
source

I had the same problem and solved it by storing all my UISwitches in an array.

Then on my viewDidAppear, I iterate over the array, disconnecting them.

 - (void)viewDidAppear:(BOOL)animated { for (UISwitch *switchView in switchMArray) { switchView.enabled = NO; } } 
0
source

Source: https://habr.com/ru/post/902229/


All Articles