2016-11-15 3 views
0

私はすぐにSSRadioButtonsControllerをXcodeに埋め込みました。これをUIAlertViewにいくつかのテキストで表示します。ラジオボタンのスウィフト

私はこれをしましたが、全く動作しません。

@IBAction func infoClicked(sender: UIButton) { 
    self.displayAlert("My Health Action Plan Detail", message: "A Health Action Plan is personal plan describing what you need to do to stay healthy. Using the plan can help you focus your health activities.") 

    var radioButtonController = SSRadioButtonsController() 
    radioButtonController.setButtonsArray([button1!,button2!,button3!]) 
    var currentButton = radioButtonController.selectedButton() 
} 

私は@mattはあなたがUIAlertViewまたはUIAlertControllerをインターフェースに追加することはできません言ったようにアラートビューに並んでテキストを

+1

UIAlertViewをインターフェイスに追加することはできません。いずれの場合も、UIAlertViewは完全に無効です.UIAlertControllerを使用する必要があります。しかし、_your_の場合は、カスタム表示のView Controllerを使用する必要があります。 – matt

+0

私はそれを持っています。しかし、ラジオボタンを追加するのを手伝ってください:) –

答えて

1

をいくつかのラジオボタンを表示する必要があります。そしてssradionボタンを追加すると、このように表示されます。

 let radioButton = SSRadioButton(frame: CGRect(x: 0, y: 0, width: 100, height: 20)) 
     radioButton.circleRadius = 8 
     radioButton.circleColor = UIColor.redColor() 
     radioButton.setTitle("1", forState: .Normal) 
     radioButton.setTitleColor(UIColor.blackColor(), forState: .Normal) 

     let radioButton1 = SSRadioButton(frame: CGRect(x: 0, y: 0, width: 100, height: 20)) 
     radioButton1.circleRadius = 8 
     radioButton1.circleColor = UIColor.redColor() 
     radioButton1.setTitle("2", forState: .Normal) 
     radioButton1.setTitleColor(UIColor.blackColor(), forState: .Normal) 

var radioButtonController = SSRadioButtonsController(buttons: radioButton, radioButton1) 
radioBtnController.delegate = self 

self.view.addSubView(radioButton) 
self.view.addSubView(radioButton1) 

を表示するラジオボタンを追加し、クリックされたボタンを検出したい場合は、SSRadioButtonControllerDelegate方法didSelectButtonを実装する必要があります。

+0

radioButton、radioButton1の無効なデーレーションは何ですか? @IBOutlet弱いvarラジオボタンを使用しました:SSRadioButton! が表示されますが、エラー –

+0

が表示されます。この問題はViewDIdLoad内に保持することで解決しますが、アプリケーションを実行した後にボタンが表示されないのはなぜですか –

+0

回答ありがとうございます:) –