Swift로 To Do 목록(Xcode6beta4Tabbed Application, UItableView, UITExtField)을 만들었습니다.
Summary
Github
Other Contents about Swift
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.swiftimport 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))
}
}
Reference
이 문제에 관하여(Swift로 To Do 목록(Xcode6beta4Tabbed Application, UItableView, UITExtField)을 만들었습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/kiiita/items/22bcb7c503eaa2f2d423텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)