Ios 在应用程序进入后台之前允许用户输入
我有一个CoreData应用程序,它有一个相当长的数据字段列表。当用户编辑字段但试图退出DetailViewController而不保存编辑时,我会发出警报,询问他们是否真的要放弃更改。这很好,但是如果用户点击home键,编辑就会丢失。我试图在应用程序进入后台之前发出警报,但无法延迟进入后台以允许用户输入。是否可以在等待用户输入时延迟应用程序进入后台 以下是我尝试过的:Ios 在应用程序进入后台之前允许用户输入,ios,swift,uialertcontroller,Ios,Swift,Uialertcontroller,我有一个CoreData应用程序,它有一个相当长的数据字段列表。当用户编辑字段但试图退出DetailViewController而不保存编辑时,我会发出警报,询问他们是否真的要放弃更改。这很好,但是如果用户点击home键,编辑就会丢失。我试图在应用程序进入后台之前发出警报,但无法延迟进入后台以允许用户输入。是否可以在等待用户输入时延迟应用程序进入后台 以下是我尝试过的: func applicationWillResignActive(_ notification : Notification)
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确实给了你的应用一些时间来清理或保存数据,但没有足够的时间用于用户交互。原因是用户确实进行了交互,并希望退出您的应用程序。可能会保存用户输入的数据并在返回时显示,但不要试图阻止用户退出。否。不可能
iOS确实给了你的应用一些时间来清理或保存数据,但没有足够的时间用于用户交互。原因是用户确实进行了交互,并希望退出您的应用程序。可能会保存用户输入的数据,并在用户返回时显示这些数据,但不要试图阻止用户退出。可能会重复您是否可以更改重置编辑字段的位置?当用户离开详细视图屏幕时,在屏幕上显示“你确定吗?”是很有意义的,但在按下“主页”按钮后,将用户返回到与字段完全相同的点-详细视图屏幕也是很有意义的。可能重复的编辑字段是否可以更改重置编辑字段的位置?当用户离开详细视图屏幕时,显示“确定吗?”是很有意义的,但在按下home(主页)按钮后,将用户返回到与字段完全相同的point-detail view(点详细视图)屏幕也是很有意义的。