내가 alert구현을 계속 까먹어서 적어놓는다
alert 창을구성한다 (UIAlertController) -> 액션을 변수로 만들어준다 (UIAlertAction() -> 구성한 창에 넣는다 (addAction) -> 잘 보여준다 (present)
func showAlert(title: String, message: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
let ok = UIAlertAction(title: "네", style: .destructive, handler: { (_) in
for i in 0...8 {
// 각 버튼마다 값을 지워주고 -> 기본값 반환 Int는 0
UserDefaults.standard.removeObject(forKey: "emotionClickedCount\([i])")
// 변경된 값을 넣어주기
self.buttonLabels[i].text = "\(self.emotionWords[i])\(UserDefaults.standard.integer(forKey: "emotionClickedCount\([i])"))"
}
})
alert.addAction(ok)
present(alert, animated: true, completion: .none) // 까먹지 말자 ㅠ
}
'짤막 TlL' 카테고리의 다른 글
스토리보드 아이디 화면전환 안됨 (0) | 2022.07.21 |
---|---|
userDefaults 코드조각 (0) | 2022.07.21 |
alert cancel (0) | 2022.07.21 |
코드 접어놓기 (0) | 2022.07.16 |
system Color (0) | 2022.07.16 |