我需要捕捉动态单元格中的开关的修改。 该应用程序具有动态单元格,可列出找到的所有BLE设备。
BLE设备应该能够通过开关打开/关闭。
现在是问题,我无法通过Outlet或Action捕获开关。
如何从动态单元格中捕获更改。
问题的UI看起来像这样: UI with dynamic cell
我找到了可以抓住水龙头的地方,但在那里我无法使用我的方法,因为在类类型UITableViewCell CoreBluetooth不受支持,我无法填写CoreBluetooth方法的属性。
import UIKit
class remoteCellTableViewCell: UITableViewCell{
//MARK: Properties
@IBOutlet weak var remoteCellLabel: UILabel!
@IBOutlet weak var remoteCellImageView: UIImageView!
@IBOutlet weak var remoteCellSwitch: UISwitch!
@IBOutlet weak var remoteCellPower: UIProgressView!
override func awakeFromNib() {
super.awakeFromNib()
}
//HERE I CAN CATCH THE SWITCH TAP BUT I CAN'T USE CoreBluetooh IN THIS CLASS
@IBAction func onOff(sender: AnyObject) {
//OBJECT FROM THE CLASS FOR CONNECT AND SEND TO THE PERIPHERAL
var connection: ViewController = ViewController()
connection.viewDidLoad()
//CANT FILLOUT THE ATTRIBUTES BECAUSE OF MISSING COREBLUETOOTH SUPPORT
//-->
connection.centralManagerDidUpdateState(<#T##central: CBCentralManager##CBCentralManager#>)
connection.centralManager(<#T##central: CBCentralManager##CBCentralManager#>, didDiscoverPeripheral: <#T##CBPeripheral#>, advertisementData: <#T##[String : AnyObject]#>, RSSI: <#T##NSNumber#>)
connection.centralManager(<#T##central: CBCentralManager##CBCentralManager#>, didConnectPeripheral: <#T##CBPeripheral#>)
connection.centralManager(<#T##central: CBCentralManager##CBCentralManager#>, didDiscoverPeripheral: <#T##CBPeripheral#>, advertisementData: <#T##[String : AnyObject]#>, RSSI: <#T##NSNumber#>)
connection.centralManager(<#T##central: CBCentralManager##CBCentralManager#>, didConnectPeripheral: <#T##CBPeripheral#>)
connection.peripheral(<#T##peripheral: CBPeripheral##CBPeripheral#>, didDiscoverServices: <#T##NSError?#>)
connection.peripheral(<#T##peripheral: CBPeripheral##CBPeripheral#>, didDiscoverCharacteristicsForService: <#T##CBService#>, error: <#T##NSError?#>)
connection.peripheral(<#T##peripheral: CBPeripheral##CBPeripheral#>, didUpdateValueForCharacteristic: <#T##CBCharacteristic#>, error: <#T##NSError?#>)
connection.peripheral(<#T##peripheral: CBPeripheral##CBPeripheral#>, didWriteValueForDescriptor: <#T##CBDescriptor#>, error: <#T##NSError?#>)
//->
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
答案 0 :(得分:0)
使用标签获取开关状态。这是我用于获取按钮单击操作的代码。喜欢这个
在 cellForRowAtIndexPath 中为该按钮指定标记。
cell.absentButton.tag = indexPath.row
在按钮操作中获取按钮行
if let button = sender as? UIButton {
if button.selected {
// set selected
let row = sender.tag
}
}
通过此,您可以获得更改的开关。