iOS_Apprentice_2_Checklists学习总结(1)
2014-11-07 22:24
148 查看
正式开始学习Swift之后第一次在博客上写下学习心得,遵照其他前辈的意见。写在这里主要是帮助自己记忆程序的结构和编程流程,因为发现跟着教程走到后来就只剩下看一步做一步,完全没有全局概念,并且迅速的将前面所学的知识忘记,所以要在这里不断的重复逻辑来加强记忆。大不了把所有代码背下来一遍一遍写,总会进步吧...
目前的进度是创建了ChecklistViewController.swift和ChecklistItem.swift两个文件,storyboard中有一个UITableView,制作了5个带Checkmark的项,点击可以勾选和去勾选(Checkmark)。
代码复写:
class ChecklistViewController: UITableViewController {
var Items: [ChecklistItem]
required init (coder aDecoder: NSCoder) {
var items = [ChecklistItem]()
let row0item = ChecklistItem()
row0item.text = "Walk the dog"
row0item.checked = false
super.init(coder aDecoder)
}
override func tableView(tableView: UITableView, numberOfRowSection section: Int) -> Int {
return items.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("ChecklistItem") as UITableViewCell
let item = items[indexPath.row]
let label = cell.viewwithTag(1000) as UILabel
label.text = item.text
configureTextForCell(cell, withChecklistItem: item)
configrueCheckmarkForCell(cell, withChecklistItem: item)
return cell
}
override func tableView(tableView: UITableView didSelectRowAtIndexPath indexPath: NSIndexPath) {
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
let item = items[indexPath.row]
item.toggleChecked()
configureCheckmarkForCell(cell, withChecklistItem: item)
}
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
func configureCheckmarkForCell(cell: UITableViewCell, withChecklistItem item: ChecklistItem) {
if item: checked {
cell.accessoryType = .Checkmark
} else {
cell.accessoryType = .None
}
}
func configureTextForCell(cell: UITableViewCell, withChecklistItem item: ChecklistItem) {
let label = cell.viewWithTag(1000) as UILabel
label.text = item.text
}
}
class ChecklistItem {
var text = ""
var checked = false
func togglechecked() {
checked = !checked
}
}
目前的进度是创建了ChecklistViewController.swift和ChecklistItem.swift两个文件,storyboard中有一个UITableView,制作了5个带Checkmark的项,点击可以勾选和去勾选(Checkmark)。
代码复写:
ChecklistViewController.swift
import UIKitclass ChecklistViewController: UITableViewController {
var Items: [ChecklistItem]
required init (coder aDecoder: NSCoder) {
var items = [ChecklistItem]()
let row0item = ChecklistItem()
row0item.text = "Walk the dog"
row0item.checked = false
super.init(coder aDecoder)
}
override func tableView(tableView: UITableView, numberOfRowSection section: Int) -> Int {
return items.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("ChecklistItem") as UITableViewCell
let item = items[indexPath.row]
let label = cell.viewwithTag(1000) as UILabel
label.text = item.text
configureTextForCell(cell, withChecklistItem: item)
configrueCheckmarkForCell(cell, withChecklistItem: item)
return cell
}
override func tableView(tableView: UITableView didSelectRowAtIndexPath indexPath: NSIndexPath) {
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
let item = items[indexPath.row]
item.toggleChecked()
configureCheckmarkForCell(cell, withChecklistItem: item)
}
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
func configureCheckmarkForCell(cell: UITableViewCell, withChecklistItem item: ChecklistItem) {
if item: checked {
cell.accessoryType = .Checkmark
} else {
cell.accessoryType = .None
}
}
func configureTextForCell(cell: UITableViewCell, withChecklistItem item: ChecklistItem) {
let label = cell.viewWithTag(1000) as UILabel
label.text = item.text
}
}
ChecklistItem.swift
import Foundationclass ChecklistItem {
var text = ""
var checked = false
func togglechecked() {
checked = !checked
}
}
相关文章推荐
- iOS_Apprentice_2_Checklists学习总结(4)
- iOS_Apprentice_2_Checklists学习总结(3) protocol解释
- iOS_Apprentice_2_Checklists学习总结(5)建立存储数据用的路径
- iOS Apprentice Second Edition 第2版ios7 史诗级iOS教程+源码
- Swift(iOS_Apprentice)学习笔记
- The iOS Apprentice:Getting Started
- Basic FortiOS 2.80 OSPF configuration
- FortiOS v3.0 HA Cluster virtual MAC addresses
- Using the FortiOS built-in packet sniffer
- 交换机IOS升级实例及相关文件命令
- Limiting YouTube bandwidth for fortios 3.0
- Configuring Secure Shell on Cisco IOS Routers
- 解析思科IOS操作顺序
- 浅谈 unix, linux, ios, android 区别和联系
- IOS恢复备份使用帮助
- ccna最新真题(2)Basic IOS Configuration