今天学习了添加按钮和AddItem.swift的编写,由于有很多需要设置的东西不太好写上来,就只上代码了
AddItemViewController.swift
import UIKit
class AddItemViewController: UITableViewController, UITextFieldDelegate {
@IBAction fun cancel() {
dismissViewControllerAnimated(true, completion: nil)
}
@IBAction func done() {
dismissViewControllerAnimated(true, completion: nil)
}
@IBOutlet weak var doneBarButton: UIBarButtonItem!
override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
return nil
}
func textField(textField: UITextField, shouldCharactersInRange range: NSRange, replacementString string:String) -> Bool {
let oldText: NSString = textField.text
let newText: NSString = oldText.stringByReplacingCharactersInRange(range, withString: string)
doneBarButton.enabled = (newtext.length > 0)
return true
}
}