2016-11-21 128 views
0

对于radiobuttons我已经在按钮中使用类和指示器按钮我已经使用了标签。 这些都是我的TextView我如何获得单选按钮的文本视图的ID点击

@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! 

只要我按ok键,我需要保存在某个地方的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 
    } 

这是我正在做的正确方法。还是有其他方法。请建议我。

+0

所以你的UI加入了textview和Radiobutton。 –

+0

对于这种情况,我更喜欢完成块。 – Jageen

回答

1

而是在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

希望这有助于。

+0

是我的错误。我的模拟器现在不工作?我会稍后再检查。谢谢你的帮助。 –

+0

IBOutlet weak var TextViewWeekly:UILabel!此标签将Weekley视为文本视图,其各自的按钮为IBOutlet弱变量RadioBtnWeekly:SSRadioButton!那么根据你的建议,我已经实施了SSRadioButton。但每当我点击任何按钮打印(TextViewWeekly.text)给null.What我做错了在这里.. –

+0

是iboutlet映射在故事板 – Vinodh

相关问题