永远不会关闭的UISwitch

时间:2011-05-13 11:36:21

标签: objective-c cocoa-touch uiswitch

我使用以下代码创建了一个UISwitch:

CGRect switchFrame = CGRectMake(200, 10, 94, 27);
UISwitch *yesNo = [[[UISwitch alloc] initWithFrame:switchFrame] autorelease];
[yesNo addTarget:self action:@selector(handleSwitch:) forControlEvents:UIControlEventValueChanged];

但是,无论切换状态如何,on属性始终返回YES,即使它在视觉上NO

事件处理程序如下所示:

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

设置displayCompleted属性:

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

可能导致这种情况的原因是什么?

1 个答案:

答案 0 :(得分:0)

我犯了一个愚蠢的错误:在reloadData之后重新创建单元格时,创建了UISwitch而没有反映displayCompleted属性的当前状态。

相关问题