我想添加一個UISwitch到我的設置視圖控制器。該開關看起來與iOS上的「設置」應用程序中的飛行模式切換相同。我不確定實現這一點的最佳方式是什麼。將開關添加到UITableViewCell:故事板vs代碼
我之間進行選擇:
- 代碼
- 創建故事板自定義單元格添加UISwitch和開關
這裏是我的雨燕代碼添加創建出口切換到UITableViewCell:
let soundSwitch = UISwitch(frame: CGRectZero)
soundSwitch.addTarget(self, action: "test:", forControlEvents: UIControlEvents.ValueChanged)
// I created an outlet for the cell that will contain a switch
soundCell.accessoryView = tickingSoundSwitch
什麼是優點和缺點使用這些解決方案?
爲什麼不在storyBoard中添加UISwitch併爲它創建一個IBAction?而不是增加目標 –