ios - How to make data I enter in a UITextField inside a UIAlertController persist through resets in Swift? -
i have been trying integrate pinboard bookmarks view (by parsing rss feed , displaying in tableview) in browser app. username , api token feed have uialertcontroller in settings view of app. details entered preserved through session if force quit app multitasking view, details deleted. how can make them stay?
this code i'm using uialertcontroller:
@ibaction func pinboarduserdetailsrequestalert(sender: anyobject) { //create alertcontroller var pinboardusernamefield :uitextfield? var pinboardapitokenfield :uitextfield? let pinboarduserdetailssheetcontroller: uialertcontroller = uialertcontroller(title: "pinboard details", message: "please enter pinboard username , api token access bookmarks", preferredstyle: .alert) //add text field pinboarduserdetailssheetcontroller.addtextfieldwithconfigurationhandler({(usernamefield: uitextfield!) in usernamefield.placeholder = "username" var parent = self.presentingviewcontroller as! viewcontroller usernamefield.text = parent.pinboardusername pinboardusernamefield = usernamefield }) pinboarduserdetailssheetcontroller.addtextfieldwithconfigurationhandler({(apitokenfield: uitextfield!) in apitokenfield.placeholder = "api token" var parent = self.presentingviewcontroller as! viewcontroller apitokenfield.text = parent.pinboardapitoken pinboardapitokenfield = apitokenfield }) pinboarduserdetailssheetcontroller.addaction(uialertaction(title: "cancel", style: .cancel, handler: nil)) pinboarduserdetailssheetcontroller.addaction(uialertaction(title: "done", style: .default, handler: { (action) -> void in // whatever want inputtextfield (remember unwrap optional) var parent = self.presentingviewcontroller as! viewcontroller parent.pinboardapitoken = pinboardapitokenfield?.text parent.pinboardusername = pinboardusernamefield?.text })) //present alertcontroller self.presentviewcontroller(pinboarduserdetailssheetcontroller, animated: true, completion: nil) }
this question has been answered portland runner in comments question. solution worked save text using nsuserdefaults.
thanks portland runner! :)
Comments
Post a Comment