에 전화하지.UIAlertview 위임 방법은 내가 두 개의 컨트롤러</p> <p><code>VC A</code>이 자식보기 컨트롤러
VC B
에서 경고를 표시 할 때 경고 단추를 클릭 할 때 대리자 메서드가 호출되지 않습니다.
에 전화하지.UIAlertview 위임 방법은 내가 두 개의 컨트롤러</p> <p><code>VC A</code>이 자식보기 컨트롤러
VC B
에서 경고를 표시 할 때 경고 단추를 클릭 할 때 대리자 메서드가 호출되지 않습니다.
protocol alertViewDelegate:class {
func alertView(View: UIAlertView!, clickedButtonAtIndex buttonIndex: Int)
}
VC B의 대리자를 구현
weak var delegate:alertViewDelegate() ?= nil
부모 클래스 VC (A)에 경고보기 위임 객체를 생성 및 VC B에서 당신은 AlertView
을 설정하는
let alertview = alertView()
alertview.delegate = self
을 위임 객체를 설정 자체 위임, 자체 의미 Child
, 대리인을 VC A로 변경하십시오.
alertView.delegate = self.parent?.parent
단계로 다음 단계를 따르
protocol AlertViewProtocol:class {
func alertView(View: UIAlertView!, clickedButtonAtIndex buttonIndex: Int)
}
이 같은 VC-B 클래스에 VAR를 추가로
이 VC-B에 프로토콜 만들기를 :
var delegate: AlertViewProtocol?
de VC-B의 임의의 클래스 방법에서 legate는 데이터를 수신 방법 (즉, VC-A의 모든 방법).이 프로토콜은 프로토콜을 채택하는 모든 방법입니다.
:class ViewControllerA: UIViewController, AlertViewProtocol {
...
...
}
는 VC-A의 대리자 메서드를 구현 :
delegate?.alertView(View: UIAlertView!, clickedButtonAtIndex buttonIndex: Int)
// Above statement is like a method calling (on delegate var), use your parameters accordingly
이 (VC-A, 여기에) 당신의 잡 클래스의 프로토콜을 채택 : 대리자를 사용하는이 패턴에 따라
func alertView(View: UIAlertView!, clickedButtonAtIndex buttonIndex: Int) {
// Do your stuff
// when you click on the designated button in your VC-B, this method will be invoked
}
VC-B 개체를 인스턴스화 할 VC-A에서 대리인을 설정하십시오. 여기
이
vcb?.delegate = self
이 매우 중요하다 :처럼 내 경우입니다.self
으로 개체의 대리자 속성을 설정하는 것을 잊어 버리면 위임 프로세스가 작동하지 않습니다.
@IBAction func showVCB(sender: AnyObject) {
let vcb: ViewControllerB? = self.storyboard?.instantiateViewControllerWithIdentifier("viewcontrollerB") as? ViewControllerB
vcb?.delegate = self
self.presentViewController(vcb!, animated: true, completion: nil)
}
희망은,이 대표가 작동하는 방법의 과정을 이해하기위한 당신을 도와줍니다.
'AlertView' 코드를 질문에 추가하십시오. –
전체 코드를 추가하십시오. 어떻게 위임 메서드를 설정하고 호출합니까? – iphonic
FUNC의 showAlert() { var에 createAccountErrorAlert : UIAlertView = UIAlertView() createAccountErrorAlert.delegate = 자기 createAccountErrorAlert.tag = sender.tag createAccountErrorAlert.accessibilityIdentifier = "ReportAbuse" createAccountErrorAlert.title는 = createAccountErrorAlert.message = "확인" 내가 즉, VC B 위임 방법 아이 VC에서 showAlert()를 호출 할 때 –