[英]Swift: Adding a UIButton in each cell while having a UITableViewCell in the code but not in the storyboard
[英]Adding a switch to UITableViewCell: storyboard vs code
我想將UISwitch添加到我的設置視圖控制器中。 該開關的外觀與iOS上“設置”應用中的“飛行模式”切換相同。 我不確定實現此目標的最佳方法是什么。
我選擇:
這是我的Swift代碼,用於向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
使用這些解決方案的優缺點是什么?
我的建議是使用
1.UISwitch和IBAction一起放在情節提要中 ,如果使用這種方法,事情變得容易了,您無需添加目標,也不必添加很多代碼。
要么
2.完全依賴代碼 ,使用這種方法,您的UISwitch不會與情節提要的UI緊密結合。 即使在將來,如果您想更改情節提要中的UI內容,也無需為UISWitch進行任何更改,即,您無需使用基於純代碼的方法附加所有這些IBAction和插座內容(前提是您提供UISwitch要求不變)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.