对于radioButtons,我在按钮中使用了Class,而对于按钮,我使用了标签。 这些是My TextView
@IBOutlet weak var TextViewEveryNewMessage: UILabel! @IBOutlet weak var TextViewWeekly: UILabel! @IBOutlet weak var TextViewDaily: UILabel! @IBOutlet weak var TextViewMonthly: UILabel!这些是我的收音机按钮
@IBOutlet weak var RadioBtnMonthly: SSRadioButton! @IBOutlet weak var RadioBtnWeekly: SSRadioButton! @IBOutlet weak var RadioBtnDefaultChecked: SSRadioButton! @IBOutlet weak var RadioBtnDaily: SSRadioButton!一旦我按下确定按钮,我需要在某处保存checkedRadio按钮文本,我就这样做了。
@IBAction func OkButton(sender: UIButton) { SwiftSpinner.show(kLoadingText) if RadioBtnDefaultChecked.selected{ preferencesConditions.notificationFrequency = self.TextViewEveryNewMessage.text }else if RadioBtnDaily.selected{ preferencesConditions.notificationFrequency = self.TextViewDaily.text }else if RadioBtnWeekly.selected{ preferencesConditions.notificationFrequency = self.TextViewWeekly.text }else{ preferencesConditions.notificationFrequency = self.TextViewMonthly.text }这是我正在做的正确方法。还是有其他办法。 请建议我。
For the radioButtons I have used Class in the button and for the indicator to buttons i have used the labels. These are My TextView
@IBOutlet weak var TextViewEveryNewMessage: UILabel! @IBOutlet weak var TextViewWeekly: UILabel! @IBOutlet weak var TextViewDaily: UILabel! @IBOutlet weak var TextViewMonthly: UILabel!These are my Radio Buttons
@IBOutlet weak var RadioBtnMonthly: SSRadioButton! @IBOutlet weak var RadioBtnWeekly: SSRadioButton! @IBOutlet weak var RadioBtnDefaultChecked: SSRadioButton! @IBOutlet weak var RadioBtnDaily: SSRadioButton!As soon as i press the ok button i need to save the checkedRadio Button text somewhere and i have done it like this.
@IBAction func OkButton(sender: UIButton) { SwiftSpinner.show(kLoadingText) if RadioBtnDefaultChecked.selected{ preferencesConditions.notificationFrequency = self.TextViewEveryNewMessage.text }else if RadioBtnDaily.selected{ preferencesConditions.notificationFrequency = self.TextViewDaily.text }else if RadioBtnWeekly.selected{ preferencesConditions.notificationFrequency = self.TextViewWeekly.text }else{ preferencesConditions.notificationFrequency = self.TextViewMonthly.text }Is this correct way i am doing.Or there are any other approach. Please suggest me.
最满意答案
而不是在OkButton(sender: UIButton)为preferencesConditions.notificationFrequency分配值,你应该在每个SSRadioButton按钮中执行它,这是通过调用SSRadioButtonControllerDelegate - didSelectButton :
func didSelectButton(aButton: UIButton?) { print(aButton) if aButton === RadioBtnDefaultChecked { preferencesConditions.notificationFrequency = self.TextViewEveryNewMessage.text }else if aButton === RadioBtnDaily { preferencesConditions.notificationFrequency = self.TextViewDaily.text }else if aButton === RadioBtnWeekly { preferencesConditions.notificationFrequency = self.TextViewWeekly.text }else{ preferencesConditions.notificationFrequency = self.TextViewMonthly.text } }不要忘记将委托符合viewController:
var radioButtonController: SSRadioButtonsController? override func viewDidLoad() { radioButtonController = SSRadioButtonsController(buttons: RadioBtnDefaultChecked, RadioBtnDaily, RadioBtnWeekly) radioButtonController!.delegate = self radioButtonController!.shouldLetDeSelect = true }IBAction应该像:
@IBAction func OkButton(sender: UIButton) { SwiftSpinner.show(kLoadingText) }有关更多信息,请检查SSRadioButtonsController 。
希望这有帮助。
Instead of assigning a value for preferencesConditions.notificationFrequency in OkButton(sender: UIButton), you should do it in each of the SSRadioButton buttons and that's by calling SSRadioButtonControllerDelegate - didSelectButton:
func didSelectButton(aButton: UIButton?) { print(aButton) if aButton === RadioBtnDefaultChecked { preferencesConditions.notificationFrequency = self.TextViewEveryNewMessage.text }else if aButton === RadioBtnDaily { preferencesConditions.notificationFrequency = self.TextViewDaily.text }else if aButton === RadioBtnWeekly { preferencesConditions.notificationFrequency = self.TextViewWeekly.text }else{ preferencesConditions.notificationFrequency = self.TextViewMonthly.text } }Don't forget to conform the delegate to the viewController:
var radioButtonController: SSRadioButtonsController? override func viewDidLoad() { radioButtonController = SSRadioButtonsController(buttons: RadioBtnDefaultChecked, RadioBtnDaily, RadioBtnWeekly) radioButtonController!.delegate = self radioButtonController!.shouldLetDeSelect = true }The IBAction should be like:
@IBAction func OkButton(sender: UIButton) { SwiftSpinner.show(kLoadingText) }For more information, check SSRadioButtonsController.
Hope this helped.
更多推荐
发布评论