Objective c 永不熄灭的开关
我使用以下代码创建了一个UISwitch:Objective c 永不熄灭的开关,objective-c,cocoa-touch,uiswitch,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];
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];
}
可能是什么原因造成的?我犯了一个愚蠢的错误:在重新加载数据后重新创建单元格时,UI开关的创建没有反映displayCompleted属性的当前状态。我认为您提供的代码没有任何问题。那么
-handleSwitch:
方法或实际检索开关状态的部分呢?我只包含了事件处理程序及其设置的属性。