暑期项目开发实训 Day9
来源:互联网 发布:怎么抢购淘宝一元拍 编辑:程序博客网 时间:2024/05/18 18:53
今天按理说应该完成第三个demo的,不过由于下午投了一份简历,晚上练了一下背包问题,所以进度搁置了。
目前进度落后了80页。
02 部分: Tagging Locations
这一部分我们想做一个动画效果:
当添加Location描述后,点击Done,屏幕会出现一个透明框提示,经过0.6秒的延迟回到开始页。
具体如下:
书上说:TheCategoryPickerViewController currently does not have a way to communicate backto the LocationDetailsViewController that the user picked a new category.
显然,这里是因为缺少了delegate protocol
但是IOS学徒的作者介绍了工作量更少的一种方法:unwind segues。
Unwindsegues are pretty cool and often easier than using a delegate protocol,
Especiallyfor simple picker screens such as this one.
HUD( Heads-Up Display)
// prepare for sender (unwind segue) override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "PickCategory" { let controller = segue.destination as! CategoryPickerViewController controller.selectedCategoryName = categoryName } }
03 部分:Core Data
这一部分首先介绍了Swift的值类型和引用类型。
常量——值类型,不可改变。引用类型,可以改变。
引用类型本身为常量时,不能放入一个对象中。
值类型是浅拷贝。(对象相等,你改我不改)
引用类型是深拷贝。(对象同一,你改我也改)
记住:类创建的对象是引用类型,其他是值类型。
然后就是下载Liya. 图形化界面 SQLite。链接数据库。
以达到数据持久化, 保存Location的描述。
04 部分:Locations Tab
我们为了操作tableView中的cell,可以加tag。
但是为什么不考虑把cell也变成对象呢?
以下是LocationCell:
// 不用 viewWithTag func configure(for location: Location) { if location.locationDescription.isEmpty { descriptionLabel.text = "(No Description)" } else { descriptionLabel.text = location.locationDescription } if let placemark = location.placemark { var text = "" if let s = placemark.subThoroughfare { text += s + " " } if let s = placemark.thoroughfare { text += s + "," } if let s = placemark.locality { text += s } addressLabel.text = text } else { addressLabel.text = String(format: "Lat: %.8f,Long: %.8f",location.latitude,location.longitude) } }
最后记录一下慢启动的问题:(lazy变量)
// var locations = [Location]() //replace with: // lazily loading obj. until you first use them. // this makes your apps quicker to start and it saves memory. lazy var fetchedResultsController: NSFetchedResultsController<Location> = { let fetchRequest = NSFetchRequest<Location>() let entity = Location.entity() fetchRequest.entity = entity let sortDescriptor1 = NSSortDescriptor(key: "category", ascending: true) let sortDescriptor2 = NSSortDescriptor(key: "date", ascending: true) fetchRequest.sortDescriptors = [sortDescriptor1,sortDescriptor2] fetchRequest.fetchBatchSize = 20 let fetchedResultsController = NSFetchedResultsController( fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: "category", ///change cacheName: "Locations") fetchedResultsController.delegate = self return fetchedResultsController }()
- 暑期项目开发实训 Day9
- 暑期项目开发实训 Day9
- 暑期项目开发实训 Day1
- 暑期项目开发实训 Day2
- 暑期项目开发实训 Day3
- 暑期项目开发实训 Day4
- 暑期项目开发实训 Day4
- 暑期项目开发实训 Day5
- 暑期项目开发实训 Day6
- 暑期项目开发实训 Day7
- 暑期项目开发实训 Day8
- 暑期项目开发实训 Day10
- 暑期项目开发实训 Day11
- 暑期项目开发实训 Day12
- 暑期项目开发实训 Day13
- 暑期项目开发实训 Day14
- 暑期项目开发实训 Day15
- 暑期项目开发实训 Day16
- 水塘抽样算法
- markdown 记录
- 7/3日总结
- 暑期项目开发实训 Day9
- 生成随机数
- 暑期项目开发实训 Day9
- [bzoj1324]Exca王者之剑
- Android上的OpenGLES程序--开发环境介绍
- VS2008使用技巧汇总
- 干货 | 自更新CC 2015.3以上版本,都默认自动安装C盘,真的无法转移其他的盘吗?
- [Matlab]Invalid mex-file 找不到指定的模块
- Java 领域从传统行业向互联网转型你必须知道的事儿 我为什么要写这篇文章 武林中,"天下武功出少林"指各门各派的武功都与少林武学有一定的渊源,技术也是相同的道理,对于Java领域的应用而言,传统
- epoll服务器
- Spring 任务调度