我使用以下代码创建了一个 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];
}
这可能是什么原因造成的?