iOS_Apprentice_2_Checklists学习总结(2)

来源:互联网 发布:魏氏熏鸡淘宝网 编辑:程序博客网 时间:2024/06/14 06:46

今天学习了添加按钮和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

}

}

0 0