Swift로 To Do 목록(Xcode6beta4Tabbed Application, UItableView, UITExtField)을 만들었습니다.

13943 단어 XcodeSwift

Summary

  • Tabbed Application
  • ToDo 등록
  • 스왑을 통해 ToDo
  • 제거

    Github

  • ToDoList_Swift by @kiiita
  • Other Contents about Swift

  • Swift 및 Parse트위터 같은 메일 기능(Xcode6beta4,Parse.com)을 com으로 만들어 봤어요.
  • Swift의 Notification에서 Hello, World, 3개의 동작을 시도했다(Xcode6beta4)
  • Source


    FirstViewController.swift
    //
    //  FirstViewController.swift
    //  My Task List
    //
    //  Created by kiiita on 2014/08/09.
    //  Copyright (c) 2014年 kiiita. All rights reserved.
    //
    
    import UIKit
    
    class FirstViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
        @IBOutlet var tblTasks: UITableView!
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
        //Returning to view
        override func viewWillAppear(animated: Bool) {
            tblTasks.reloadData();
        }
    
        //UITableViewDelete
    
        func tableView(tableView: UITableView!, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath!){
    
            if(editingStyle == UITableViewCellEditingStyle.Delete){
                taskMgr.tasks.removeAtIndex(indexPath.row)
                tblTasks.reloadData();
            }
        }
    
    
        // UITableViewDataSource
        func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
            return taskMgr.tasks.count
        }
    
        func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) ->
            UITableViewCell!{
    
                let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "test")
                cell.textLabel.text = taskMgr.tasks[indexPath.row].name
                cell.detailTextLabel.text = taskMgr.tasks[indexPath.row].desc
    
                return cell
        }
    
    
    }
    
    SecondViewController.swift
    //
    //  SecondViewController.swift
    //  My Task List
    //
    //  Created by kiiita on 2014/08/09.
    //  Copyright (c) 2014年 kiiita. All rights reserved.
    //
    
    import UIKit
    
    class SecondViewController: UIViewController, UITextFieldDelegate {
    
        @IBOutlet var txtTask: UITextField!
        @IBOutlet var txtDesc: UITextField!
    
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
        //Events
        @IBAction func btnAddTask_Click(sender: UIButton) {
            println("the button was clicked")
            taskMgr.addTask(txtTask.text, desc: txtDesc.text);
            self.view.endEditing(true)
            txtTask.text = ""
            txtDesc.text = ""
            self.tabBarController.selectedIndex = 0;
        }
    
        // IOS Touch Functions
        override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
            self.view.endEditing(true)
        }
    
        //  UITextField Delegate // called when 'return' key pressed. return NO to ignore.
        func textFieldShouldReturn(textField: UITextField!) -> Bool{
            textField.resignFirstResponder();
            return true
    
        }
    
    }
    
    TaskManager.swift
    import UIKit
    
    var taskMgr: TaskManager = TaskManager()
    
    struct task {
        var name = "Un-Named"
        var desc = "Un-Described"
    }
    
    class TaskManager: NSObject {
    
        var tasks : [task] = []
    
        func addTask(name : String, desc: String){
            tasks.append(task(name: name, desc: desc))
        }
    }
    

    좋은 웹페이지 즐겨찾기