Tag: UITableViewSwift UISwitch

在Swift中点击其UISwitch时,selectUITableView的行

这个问题已经在Objective-C中find了。 但是我正在Swift工作,也有类似的问题。 一旦成功创build,当我点击它的UISwitch时,如何selectUITableView的行? 我在我的模型中有一个布尔值,并希望根据开关的开/关状态来切换布尔值。 我有一些编程创build的单元格包含开关… 视图控制器: var settings : [SettingItem] = [ SettingItem(settingName: "Setting 1", switchState: true), SettingItem(settingName: "Setting 2", switchState: true) ] override public func tableView(_tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("CustomSettingCell") as! SettingCell let settingItem = settings[indexPath.row] cell.settingsLabel.text = settingItem.settingName cell.settingsSwitch.enabled = settingItem.switchState! return cell } 基于SettingItem.swift中的模型: class […]