2016-08-18 3 views
2

UI 경고를 구현하는 동안 몇 가지 문제가 발생했습니다. 나는 Xcode 8 베타 4에서 신속한 3.0을 사용하고 있는데, 경고를 활성화하는 버튼을 시도하고 있는데, 하나의 버튼 (취소)은 다른 버튼 (ok)이 UIAction Button으로 동작을 수행하지만, 보여줄 수있는 경고를 받는다.왜이 UIAlertController가 표시되지 않습니까?

var warning = UIAlertController(title: "warning", message: "This will erase all content", preferredStyle: .Alert) 

var okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { 
    UIAlertAction in 
    NSLog("OK Pressed") 
} 

var cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { 
    UIAlertAction in 
    NSLog("Cancel Pressed") 
} 

warning.addAction(okAction) { 
    // this is where the actions to erase the content in the strings 
} 
warning.addAction(cancelAction) 

self.presentViewController(warning, animated: true, completion: nil) 

답변

3

그 코드는 스위프트와 .Alert 같은 3 가지 지금 .alert 있습니다 호환되지 않습니다. 그리고 presentViewController 방법은 상당히 다릅니다.

이렇게하면됩니다.

let warning = UIAlertController(title: "warning", message: "This will erase all content", preferredStyle: .alert) 

    let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) { 
     UIAlertAction in 
     NSLog("OK Pressed") 
     //ok action should go here 
    } 


    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) { 
     UIAlertAction in 
     NSLog("Cancel Pressed") 
    } 

    warning.addAction(okAction) 
    warning.addAction(cancelAction) 

    present(warning, animated: true, completion: nil) 

경보를 만들 때 대신 addAction(okAction) 이후에 폐쇄를 수행 한 이유가 무엇입니까?

희망이 도움이됩니다.

+0

내가 집에 돌아갈 때마다 시험해 보게 해줘서 고마워. swift3.0에 대한 도움이 아직 없다. 크게 appered되었습니다. – Yellow

관련 문제