我有警告,写入iOS 8+,我必须向iOS 7.0写相同的警报(我使用其他请求的四个警报)
有我的代码:
func AlertForNumber () {
var alertController: UIAlertController?
//
alertController = UIAlertController(title: "First", message: "Enter number", preferredStyle: .Alert)
alertController!.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
textField.text = "38"
})
let action = UIAlertAction(title: "Next", style: UIAlertActionStyle.Default, handler: {[weak self]
(paramAction: UIAlertAction!) in
if let textFields = alertController?.textFields {
let textFields = textFields as! [UITextField]
let enterText = textFields[0].text
if (count(enterText) < 12){
self?.ErrorForNumber()
} else {
self!.data.numberID = enterText
self!.data.SaveData(enterText, codetext: self!.data.codeID)
self!.json.UfR()
}
}
})
alertController?.addAction(action)
dispatch_async(dispatch_get_main_queue(), {
self.presentViewController(alertController!, animated: true, completion: nil)
})
}
在那个警报处,我必须输入我的号码,然后发送到服务器。 我必须只使用带有文本字段的警报 我必须在下次提醒时输入代码:
func AlertForCode () {
var alertController: UIAlertController?
alertController = UIAlertController(title: "Second", message: "Enter code", preferredStyle: .Alert)
alertController!.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
textField.placeholder = code_text
})
let action = UIAlertAction(title: "Next", style: UIAlertActionStyle.Default, handler: {[weak self]
(paramAction: UIAlertAction!) in
if let textFields = alertController?.textFields {
let textFields = textFields as! [UITextField]
let enterText = textFields[0].text
self!.data.codeID = enterText
self!.data.SaveData(self!.data.numberID, codetext: enterText)
self!.json.UfR()
}
})
alertController?.addAction(action)
dispatch_async(dispatch_get_main_queue(), {
self.presentViewController(alertController!, animated: true, completion: nil)
})
}
所以我必须写入iOS 7.0
答案 0 :(得分:0)
func AlertForNumber () {
let alertView = UIAlertView(title: "First", message: "Enter number", delegate: self, cancelButtonTitle: "Next")
alertView.alertViewStyle = UIAlertViewStyle.PlainTextInput
alertView.textFieldAtIndex(0)?.text = "38"
alertView.show()
}
func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
println("next")
let enterText = alertView.textFieldAtIndex(0)!.text
if (count(enterText) < 12){
self?.ErrorForNumber()
} else {
self!.data.numberID = enterText
self!.data.SaveData(enterText, codetext: self!.data.codeID)
self!.json.UfR()
}
}