如何在UITableView中的所有自定义单元格中启用UISwitch

时间:2013-01-04 09:50:25

标签: xcode uitableview uiswitch

我使用UITableView创建了custom cell。 每个自定义单元都有一个UISwitch,就像iPhone中的股票闹钟应用程序一样。 我想在我的UISwitch单元格中启用每个UITableView。 请帮帮我......

2 个答案:

答案 0 :(得分:0)

这段代码不是通用的,你应该重构它,但这是主要的想法。

- (void)enableOnlyAllTheSwitches{
    int objectsCount = [myObjectsDataStructure count];
    for (int i=0; i++; i<objectsCount){
        NSIndexPath *cellIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
        MyCustomTableViewCell *cell = [self.myTableView cellForRowAtIndexPath:cellIndexPath];
        [cell.switch setOn:YES animated:YES];
    }
}

答案 1 :(得分:0)

我找到了答案:

MyTableView.allowsSelection=NO;

MyTableView.allowsSelectionDuringEditing=YES;

这项工作非常好......

相关问题