2014-11-01 3 views
0

저는 신속한 답변을 얻지 못했으며 경고보기 강의에서 일부 자습서를 따랐습니다. 나는 alert 버튼이 클릭 될 때마다 또 다른 viewcontroller를 호출하는 것과 같은 함수를 추가하고 싶다. 그러나 나는 그 방법을 모른다.alertcontroller에서 버튼에 기능 추가

let cancelAction = UIAlertAction(title: cancelButtonTitle, style: .Cancel){ 
     action in NSLog("No!!!!") 
     let View2 = self.storyboard?.instantiateViewControllerWithIdentifier("View2") as TwoViewController 
     self.navigationController?.pushViewController(View2, animated: true) 

    } 

을 또한 기존의 뷰 컨트롤러를 선택하고 드롭 다운 메뉴에서> 삽입에> 네비게이션 컨트롤러편집을 선택 : 그래서 pls는 저

func showAlertController(){ 

    var title : String = "hi!" 
    var message : String = NSLocalizedString("Are you feeling well? ", comment:"") 
    let cancelButtonTitle = NSLocalizedString("No", comment:"") 
    let otherButtonTitle = NSLocalizedString("Yes", comment:"") 

    let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert) 

    let cancelAction = UIAlertAction(title: cancelButtonTitle, style: .Cancel){ 
     action in NSLog("No!!!!") 
    } 

    let otherAction = UIAlertAction(title: otherButtonTitle, style: .Default){ 
     action in NSLog("welcome!!! hello back") 
    } 

    alertController.addAction(cancelAction) 
    alertController.addAction(otherAction) 
    presentViewController(alertController, animated: true, completion: nil) 
} 
+0

알림을 표시하는 [UIAlertViewController] (http://www.appcoda.com/uialertcontroller-swift-closures-enum/)를 보시라. –

답변

1

이 코드를 시도 도움이됩니다.

그런 다음 새로운보기 컨트롤러를 추가하고 새로운 코코아 클래스를 만들고 TwoViewController 하위 클래스 UIViewController의 이름을 지정하십시오.

그 후 새의 ViewController를 선택하고이 당신을 도울 수 수 있음 신원 경위 enter image description here

에서이 방법을 사용자 정의합니다.

+0

ur 빠른 답장을 보내고 싶지만, 알고 싶은 것은 어떻게해야 하는가? 경고 단추를 클릭하면 다른 ViewController에 연결할 수 있습니다. 내 기능에서 취소 단추를 누르면 "아니오"가 인쇄되지만 "아니오"단추를 누르면 다른보기 제어기에 대한 링크가됩니다. – user3020676

+0

답변을 업데이트합니다. –

+0

당신의 도움에 감사드립니다 – user3020676