如何通过单击单选按钮获取文本视图的ID(How do i get the Id of text view with radio Buttons clicked)

编程入门 行业动态 更新时间:2024-10-25 08:24:09
如何通过单击单选按钮获取文本视图的ID(How do i get the Id of text view with radio Buttons clicked)

对于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.

更多推荐

本文发布于:2023-08-01 01:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1351429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   单击   单选   按钮   文本

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!