0
私はUIAlertController
のテキストフィールドを使用しています。これにより、ユーザーは、データをサーバーに送信する前にファイル名を付けるタイトルを入力できます。しかし、バックエンドはいくつかの理由でファイルを拒否し、エラーを表示する必要があります。ファイル名を入力したのと同じアラートコントローラに、サーバから戻ってくるエラーをどのように表示できますか?サーバー上UIAlertControllerによるエラー処理
class FileController: UIViewController
{
var alertController: UIAlertController?
func savePressed()
{
createAlert()
}
func createAlert()
{
self.alertController = UIAlertController(title: "Save", message: "Name your file.", preferredStyle: .Alert)
let saveAsPublicAction = UIAlertAction(title: "Make Public", style: .Default) { (_) in
let fileTitle = self.alertController!.textFields![0] as UITextField
if fileTitle.text != ""
{
self.initiateSave(fileTitle.text!, share: true)
}
}
let saveAsPrivateAction = UIAlertAction(title: "Make Private", style: .Default) { (_) in
let fileTitle = self.alertController!.textFields![0] as UITextField
if fileTitle.text != ""
{
self.initiateSave(fileTitle.text!, share: false)
}
}
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (_) in }
self.alertController!.addTextFieldWithConfigurationHandler { (textField) in
NSNotificationCenter.defaultCenter().addObserverForName(UITextFieldTextDidChangeNotification, object: textField, queue: NSOperationQueue.mainQueue()) { (notification) in
saveAsPrivateAction.enabled = textField.text != ""
saveAsPublicAction.enabled = textField.text != ""
}
}
self.alertController!.addAction(saveAsPublicAction)
self.alertController!.addAction(saveAsPrivateAction)
self.alertController!.addAction(cancelAction)
self.presentViewController(self.alertController!, animated: true, completion: nil)
}
}
func initiateSave(title:String?, share: Bool?)
{
//package file
initiatePost()
}
func initiatePost()
{
//Send file data to server. Receive any errors and handle
}
私がやっていること。私はファイル名を入力したのと同じアラートコントローラに結果をどのように表示するのだろうかと思っています。 – Brosef
@Brosef okあなたは何を意味するのか分かります。そのためには、再度 'self.presentViewController'を呼び出す必要があります。 – meda
' initiatePost'関数でエラーを受け取り、エラーが受信されたときに警告コントローラはまだ存在しています。アラートコントローラにエラーを表示するにはどうすればよいですか? – Brosef