초급 프로그래머입니다. 경고의 버튼에 작업을 추가하려고하지만 작동하지 않습니다. 경고 버튼 선택으로 레이블의 텍스트를 변경할 수 있는지 테스트하고 싶지만 작동하지 않습니다. 물론 경고와 버튼을 잘 볼 수는 있지만 버튼을 클릭 한 후에는 아무 일도 일어나지 않습니다.Swift에서 Alert의 버튼에 작업을 추가하는 방법
alertTest.delegate = self
UIAlertView
은 그것의 위임에 방법이 어떤 일을 달성하거나 이벤트 통지 호출을 의미 delegate pattern을 사용
@IBOutlet var statusLabelAlert : UILabel
var alertTest = UIAlertView()
@IBAction func alertButton(sender : AnyObject) {
alertTest.message = "Select one!"
alertTest.addButtonWithTitle("1st")
alertTest.addButtonWithTitle("2nd")
alertTest.addButtonWithTitle("3rd")
alertTest.title = "Test Alert"
alertTest.show()
}
func alertView(alertView: UIAlertView!, clickedButtonAtIndex buttonIndex: Int){
switch buttonIndex{
case 0:
statusLabelAlert.text = "1st"
case 1:
statusLabelAlert.text = "2nd"
case 2:
statusLabelAlert.text = "3rd"
default:
statusLabelAlert.text = "error"
}
}