Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 永不熄灭的开关_Objective C_Cocoa Touch_Uiswitch - Fatal编程技术网

Objective c 永不熄灭的开关

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];

我使用以下代码创建了一个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];
}

可能是什么原因造成的?

我犯了一个愚蠢的错误:在重新加载数据后重新创建单元格时,UI开关的创建没有反映displayCompleted属性的当前状态。

我认为您提供的代码没有任何问题。那么
-handleSwitch:
方法或实际检索开关状态的部分呢?我只包含了事件处理程序及其设置的属性。