Coder Social home page Coder Social logo

ios-004_todolist's Introduction

日期

  • 格式化日期方法

      func dateFromString(dateStr: String) -> NSDate? {
          
          let dateFormatter = NSDateFormatter()
          dateFormatter.dateFormat = "yyyy-MM-dd"
          return dateFormatter.dateFromString(dateStr)
      }
    
  • 国际化格式日期

      // 国际化日期模板
      let locale = NSLocale.currentLocale()
      let dateFormatterTemplate = NSDateFormatter.dateFormatFromTemplate("yyyy-MM-dd", options: 0, locale: locale)
      
      // 日期格式
      let dateFormatter = NSDateFormatter()
      dateFormatter.dateFormat = dateFormatterTemplate
      
      date?.text = dateFormatter.stringFromDate(todo.date)
    

创建本地临时数据库

  • 在类外定义

      // bean 对象数组
      var todos: [TodoModel] = []
    

TableView

  • 接口

    • UITableViewDataSource:数据源

        // TableView 行数
        public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
      

        // 相当于 Android 的 BaseAdapter 中的 getView() 方法
        public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
      
    • UITableViewDelegate

        // 手势-编辑删除 TableView 某行功能
        // 按钮-可配合横线下面方法
        func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
            
            if editingStyle == UITableViewCellEditingStyle.Delete {
                todos.removeAtIndex(indexPath.row)
                self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
            }
        }
      

        // 添加功能
        override func setEditing(editing: Bool, animated: Bool) {
            super.setEditing(editing, animated: animated)
            self.tableView.setEditing(editing, animated: animated)
        }
      
    • TableView 删除行后重新加载数据

        tableView.reloadData()
      
    • 点击编辑时跳转 ViewController 并将当前选中行信息传递

        override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
            if segue.identifier == "TodoEditor" {
                
                var vc = segue.destinationViewController as? DetailViewController
                var  indexPath = tableView.indexPathForSelectedRow
            
                if let index = indexPath {
                    vc!.todoItem = todos[index.row]
                }
            }
        }
      
    • 脚踏板移动行功能

        func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        	return editing
        }
        
        func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
            let todo = todos.removeAtIndex(sourceIndexPath.row)
            
            todos.insert(todo, atIndex: destinationIndexPath.row)
        }
      

搜索

  • 接口

      UISearchDisplayDelegate
    
  • 隐藏搜索栏

      var contentOffset = tableView.contentOffset
      contentOffset.y += searchDisplayController!.searchBar.frame.size.height
      tableView.contentOffset = contentOffset
    
  • 搜索

     	func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchString searchString: String!) -> Bool {
     		filterTodos = todos.filter() {
     			// 过滤搜索条件
     		    $0.title.rangeOfString(searchString) != nil
     		}
     		return true
     	}
     	    
     	func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
     	    // 行高
     	    return 80
     	}
    

ios-004_todolist's People

Contributors

itcatface avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.