IT/IPhone개발

[Swift] UIAlertView 바뀐 사용법

차가운남자 2016. 5. 2. 19:45

Swift 2.2 이전 버전에서는

var Alert:UIAlertView = UIAlertView(title: "제목", message: "안녕하세요.", delegate: self, cancelButtonTitle: "OK")

라고 했으면 됐지만 버전이 2.2로 바뀌면서 UIAlertController로 바뀌게 되었다.

아래와 같이 변경되었다.


let alertController = UIAlertController(title: "제목", message: "내용부분입니다.", preferredStyle: UIAlertControllerStyle.Alert)

 let DestructiveAction = UIAlertAction(title: "취소", style: UIAlertActionStyle.Destructive) { (result : UIAlertAction) -> Void in

                print("취소")

 }

 let okAction = UIAlertAction(title: "확인", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -> Void in

                print("확인")

 }

  alertController.addAction(DestructiveAction)

  alertController.addAction(okAction)

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

결과화면:

바뀌게 된 이유는 개인적으로 추측한 결과 좀더 개발자 입맛에 맞추어 코딩을하라고 수정된 것이라고 보인다!? 



'IT > IPhone개발' 카테고리의 다른 글

[Swift] Optional 사용  (0) 2016.05.04
[Swift] Segue로 값넘기기  (0) 2016.05.03
[Swift] xcode 7.3 Swift 2.2 변경된 것들  (0) 2016.04.27
[swift] 공부하기 괜찮은 사이트  (0) 2016.04.26
[Swift] TableView 파해치기  (0) 2016.04.22