데이터 필드 목록이 상당히 많은 CoreData 앱이 있습니다. 사용자가 필드를 편집하지만 편집 내용을 저장하지 않고 DetailViewController를 종료하려고 시도 할 때 실제로 변경 사항을 무시할지 묻는 경고를 표시합니다. 이 잘 작동하지만 사용자가 홈 키를 누르면 편집 내용이 손실됩니다. 앱이 백그라운드로 들어가기 전에 알림을 표시하려했지만 사용자 입력을 허용하기 위해 백그라운드로 진입을 지연시킬 수 없었습니다. 사용자 입력을 기다리는 동안 앱 입력을 백그라운드로 지연시킬 수 있습니까?앱이 백그라운드로 들어가기 전에 사용자 입력 허용
는 여기에 내가 시도 내용은 다음과 같습니다
func applicationWillResignActive(_ notification : Notification) {
//this does not work - alert is too late
cancelUnsavedEdits()
//try above
}//applicationWillResignActive
canelUnsavedEdits 방법은 매우 정직 :이 아이디어를 달성하기위한 전략에
func cancelUnsavedEdits() {
if hasChanged {
let ac = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "Delete Edits", style: .default, handler: { (action : UIAlertAction!) -> Void in
self.codeDismissTheKeyboard()
self.performSegue(withIdentifier: "unwindToMasterViewController", sender: self)
let editRecordButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.edit, target: self, action: #selector(DetailViewController.editThisRecord))
self.navigationItem.rightBarButtonItem = editRecordButton
self.navigationItem.leftBarButtonItem = nil
self.navigationItem.hidesBackButton = false
//need to remove the edits - refresh the original page
self.configureView()
}))//addAction block
ac.addAction(UIAlertAction(title: "Save Edits", style: .default, handler: { (action : UIAlertAction!) -> Void in
self.codeDismissTheKeyboard()
self.saveTheEditedRecord()
self.performSegue(withIdentifier: "unwindToMasterViewController", sender: self)
}))//addAction block
//for -ipad add code in handler to reopen the fields for editing if the cancel of the cancel is chosed
ac.addAction(UIAlertAction(title: "Cancel", style: .default, handler: { (whatever) in
//print("makeEntryFieldsEnabledYES for ipad")
self.makeEntryFieldsEnabledYES()
}))
//above for ipad
self.present(ac, animated: true, completion: nil)
} else {
self.codeDismissTheKeyboard()
//add this for ipad
self.navigationItem.rightBarButtonItem = nil
//add above for ipad
self.performSegue(withIdentifier: "unwindToMasterViewController", sender: self)
}//if hasChanged
//this for ipad
navigationItem.leftBarButtonItem = nil
//above for iPad
}//cancelUnsavedEdits
모든 지침 감상 할 수있다. iOS 10, Xcode 8.1
가능한 [iOS 홈 버튼 경고, 중복 될 수 있습니까?] (http://stackoverflow.com/questions/7112723/ios-home-button-warning-is-it-possible) –
편집 필드를 재설정 하시겠습니까? "Are you sure?"라는 말을 쓰는 것이 좋습니다. 상세보기 화면을 떠날 때 홈 버튼을 누른 후 사용자를 정확히 동일한 지점으로 되돌릴 수 있습니다. 즉, 필드가있는 상세보기 화면이 좋습니다. – dfd