【发布时间】:2011-05-13 11:36:20
【问题描述】:
我使用以下代码创建了一个 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];
}
这可能是什么原因?
【问题讨论】:
-
我认为您提供的代码没有任何问题。
-handleSwitch:方法或您实际检索开关状态的部分呢? -
我只包含了事件处理程序以及它设置的属性。
标签: objective-c cocoa-touch uiswitch