I'm placing a UISwitch
es in UITableViewCell
s 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?
For what it's worth, UISwitch's designated initializer is -initWithFrame:
— have you tried using that?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With