开发者

A UISwitch that is never off

I created a UISwitch with the following code:

CGRect switchFrame = CGRectMake(200, 10, 94, 27);
UISwitch *yesNo = [[[UISwitch alloc] initWithFrame:switchFrame] autor开发者_如何学Pythonelease];
[yesNo addTarget:self action:@selector(handleSwitch:) forControlEvents:UIControlEventValueChanged];

However, no matter the state of the switch the on property always returns YES, even when it's visually NO.

The event handler looks like this:

-(IBAction) handleSwitch: (UISwitch *) sender{
    self.displayCompleted = sender.on;
}

Which sets the displayCompleted property:

-(void) setDisplayCompleted:(BOOL)newValue{
    displayCompleted = newValue;
    [[self tableView] reloadData];
}

What might be causing this?


I was making a stupid mistake: when recreating the cell after reloadData the UISwitch was created without reflecting the current state of the displayCompleted property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜