Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New IOS5 UISwitch doesn't look disabled in a UITableViewCell

I'm placing a UISwitches in UITableViewCells and I try to disable it initially:

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

In IOS versions prior to IOS5, the (old-looking) switch is disabled and also looks disabled (dimmed) when the view appears.

In IOS5 the (new-looking) switch is disabled alright, I can't flip it, but it does not look disabled at this stage. It has the same brightness as an enabled switch.

If I enable and re-disable it later in the code (NOT in the cellForRowAtIndexPath: callback), it does look disabled (dimmed).

Am I doing something wrong or is this a bug in IOS5?

like image 262
Amiram Stark Avatar asked Nov 23 '11 17:11

Amiram Stark


2 Answers

For what it's worth, UISwitch's designated initializer is -initWithFrame: — have you tried using that?

like image 168
David Dunham Avatar answered Oct 04 '22 20:10

David Dunham


I faced up same problem with iOS 5. You can use -initWithFrame to create switch and then you can add the switch as a subview of cell contentView and (not an accesoryview and do not forget to count subviews of contentView, otherwise you could add a new uiswitch) with -addSubview: method.

like image 29
CanP Avatar answered Oct 04 '22 22:10

CanP