我用以下代码创建了一个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];
}这可能是什么原因造成的?
发布于 2011-05-13 20:24:19
我犯了一个愚蠢的错误:在reloadData之后重新创建单元格时,创建的UISwitch没有反映displayCompleted属性的当前状态。
https://stackoverflow.com/questions/5991274
复制相似问题