나는 조금 붙어있다. 나는 UIViewController
이고 UIView
을 확장하는 사용자 정의 pop.xib
이 있습니다. pop.xib
은 pop.swift
에 연결됩니다. UIViewController
버튼은 .xib
파일을 팝업합니다.신속하게 델리게이트를 사용하여 xib 파일에서 버튼을 클릭했다는 것을 UIViewController에 알리는 방법은 무엇입니까?
pop.xib
에는 데이터베이스에 데이터를 보내기 위해 클릭하는 버튼이 있습니다.
pop.xib
에서 클릭 할 때 내가 원하는
UIViewController
에
가) @IBAction func sendDataToDbAction(_ sender: Any)
을 클릭 할 때 알고
b)는 if 문 다음 현재 sendDataToDbAction
내부에서 false를 반환 할 때 UIViewController
//pop.swift
class Pop: UIView {
@IBOutlet var delegate: AnswerDelegate?
@IBAction func sendDataToDbAction(_ sender: Any)
{
if(answer == false)
{
don't send to db
alert pops up saying answer is false
}
else
{
}
}
}
에 대한 경고가 나는 pop.swift에 대리자를 설정 한
//pop.swift
@objc protocol AnswerDelegate {
func isCorrectAnswer()
}
//UIViewController
extension UIViewController:AnswerDelegate{
//set the pop.xib delegate to self
// implement func isCorrectAnswer
}
내가 원하는 것을 위임자가 어떻게 사용할 수 있는지 잘 모르겠습니다.
감사합니다.