2016-11-21 8 views
0

ラジオボタンについては、ボタンにクラスを使用し、ボタンにはインジケータとしてラベルを使用しています。 これらは、これらが私のラジオボタンとすぐに私はどこかcheckedRadioのボタンのテキストを保存する必要があり、OKボタンを押すと、私はこのようにそれを行っているようラジオ付きテキストビューのIDを取得する方法ボタンをクリック

@IBOutlet weak var RadioBtnMonthly: SSRadioButton! 
@IBOutlet weak var RadioBtnWeekly: SSRadioButton! 
@IBOutlet weak var RadioBtnDefaultChecked: SSRadioButton! 
@IBOutlet weak var RadioBtnDaily: SSRadioButton! 

ある

@IBOutlet weak var TextViewEveryNewMessage: UILabel! 
@IBOutlet weak var TextViewWeekly: UILabel! 
@IBOutlet weak var TextViewDaily: UILabel! 
@IBOutlet weak var TextViewMonthly: UILabel! 

私のTextViewです。

@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 weak var RadioBtnWeekly:SSRadioButtonです。あなたの提案に従って、私はSSRadioButtonを実装しました。しかし、いずれかのボタンをクリックするたびにPrint(TextViewWeekly.text)がnullを返します。私はここで間違っています。 –

+0

はストーリーボードにマップされたiboutletです – Vinodh

関連する問題