UIAlertViews에 대한 핸들러 선언에 대한 몇 가지 예제를 읽었으며 어쨌든 적절한 구문의 개념을 이해할 수 없습니다. SomeFunction을
- 핸들러 : {된 SomeFuncion의 행동} ("액션"는 무엇을 의미합니까?) - 핸들러 : {_ 인쇄에서 (- 핸들러
: 나는 그들이 다음 중 하나를 수행 몇 가지 예를 본 적이 "Foo!") (다시, "in"의 의미는 무엇입니까?)핸들러 선언이 작동하지 않습니다.
가장 큰 우려는 이러한 것들의 의미를 모른다는 것입니다. 현재 사용 폐쇄 또는 completion handlers하는 방법을 배울 수있는 시간이다, 코멘트에서 언급 한 바와 같이
let answerVCAlert = UIAlertController(title: "Your turn", message: "What's the answer?", preferredStyle: .alert)
let submitAnswer = UIAlertAction(title: "Submit", style: .default, handler: submitAnswer(answer: " ")) //grab from textfield
let noAnswer = UIAlertAction(title: "No Answer", style: .default, handler: submitAnswer(answer: " "))
func submitAnswer(answer: String) {
print ("The string passed is \(answer)")
//compare answer to correct answer
}
func attemptAnswer() {
answerVCAlert.addAction(submitAnswer)
answerVCAlert.addAction(noAnswer)
//answerVCAlert.addTextField //how ??? too many different examples
self.present(answerVCAlert, animated: true, completion: nil)
}
어디에서 attempAnswer 메소드를 호출합니까? –
* "이러한 것들의 의미를 모르겠습니다."* - [Closures] (https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures)를 읽고 싶습니다. html) 장을 참조하십시오. –
나는 클로저를 읽었으며, 클로저가 무엇인지 개념을 알고 있으며 자바의 람다 식에 익숙하다. 일반적으로 나를 쫓아 버리는 것은 구문의 일부입니다 (특히 "action"또는 "in"과 같은 단어를 사용하는 경우, 어디에서 동작을 정의 했는가, 또는 무엇을 의미합니까?). 미안 OP에서 불분명하다면 개념이 무엇인지 알지만 문법은 모든 사람이이 구문을 사용하는 예제를 제공하기 때문에 나에게 익숙합니다. –