以下是带有textField的UIAlertView的代码:
@IBOutlet weak var tableView: UITableView!
@IBAction func addReminder(sender: AnyObject) {
var tField: UITextField!
func configurationTextField(textField: UITextField!)
{
print("generating the TextField")
textField.placeholder = "Enter a Reminder"
tField = textField
}
func handleCancel(alertView: UIAlertAction!)
{
print("Cancelled !!")
}
var alert = UIAlertController(title: "Reminder", message: "", preferredStyle: .Alert)
alert.addTextFieldWithConfigurationHandler(configurationTextField)
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler:handleCancel))
alert.addAction(UIAlertAction(title: "Add", style: .Default, handler:{ (UIAlertAction) in
print("Done !!")
print("Item : \(tField.text!)")
}))
self.presentViewController(alert, animated: true, completion: {
print("completion block")
})
NSUserDefaults.standardUserDefaults().setObject(reminder, forKey: "toDoList")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return reminder.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
cell.textLabel?.text = reminder[indexPath.row]
return cell
}
override func viewDidAppear(animated: Bool) {
tableView.reloadData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
所以我想在UIAlertView上添加一个keyBoard。因此,当您运行代码并按下文本时,将弹出keyBoard。那我该怎么编程?