Amiram Stark
Amiram Stark

Reputation: 2208

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?

Upvotes: 6

Views: 912

Answers (3)

Andre Cytryn
Andre Cytryn

Reputation: 2705

I had the same issue and I solved it by saving all my UISwitches in an array.

Then on my viewDidAppear, I iterate through the array disabling them.

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

Upvotes: 0

CanP
CanP

Reputation: 65

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.

Upvotes: 2

David Dunham
David Dunham

Reputation: 8329

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

Upvotes: 3

Related Questions