CoreData实践(四)——查询数据
来源:互联网 发布:寡妇王二娘 知乎 编辑:程序博客网 时间:2024/06/01 10:28
我在上一篇博客中讲解了如何往SQLite数据库中插入数据,现在我们将要进行查询。
(1)代码实现如下:
import UIKitimport CoreDataclass UsersTableViewController: UITableViewController { var dataArr:Array<AnyObject>! = [] var context:NSManagedObjectContext! override func viewDidLoad() { super.viewDidLoad() context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext var f = NSFetchRequest(entityName: "Users") dataArr = context.executeFetchRequest(f, error: nil) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // MARK: - Table view data source override func numberOfSectionsInTableView(tableView: UITableView) -> Int { // #warning Potentially incomplete method implementation. // Return the number of sections. return 1 } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // #warning Incomplete method implementation. // Return the number of rows in the section. return dataArr.count } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell var name = dataArr[indexPath.row].valueForKey("name") as! String var age = dataArr[indexPath.row].valueForKey("age") as! Int var label = cell.viewWithTag(101) as! UILabel label.text = "姓名:\(name); 年龄:\(age)" return cell }}
(2)运行程序,结果如下:
。
github主页:https://github.com/chenyufeng1991 。欢迎大家访问!
1 0
- CoreData实践(四)——查询数据
- CoreData实践(五)——修改数据
- CoreData实践(六)——数据删除
- CoreData实践(三)——插入数据并使用SQLite Professional查看
- coredata 分页查询数据
- iOS CoreData 查询数据
- CoreData实践(二)——设计数据结构
- 数据库学习实践(四、五)--分页浏览、查询数据
- 数据库学习实践(四、五)--分页浏览、查询数据
- CoreData实践(一)
- Coredata第三课 数据查询
- Coredata第三课 数据查询
- XMPP框架 微信项目开发之CoreData学习——CoreData的查询方式(模糊查询,嵌套查询,分页查询)
- CoreData用法四:多表查询
- CoreData添加数据和查询数据
- 数据缓存——CoreData的使用
- 数据存储——CoreData的使用
- 认识CoreData—初识CoreData
- log4j配置文件和日志级别分离
- xml
- Jersey: MessageBodyWriter not found for media type=application/json
- centos7 mysql5.6
- 利用白名单绕过360实例
- CoreData实践(四)——查询数据
- rdf
- js之History对象
- android把activity和资源文件打包成jar包给其他项目使用
- 【bzoj1191】【NHOI2006】【超级英雄】【二分图匹配】
- 用js控制frame框架自适应高度
- ebs中SLA解释
- Eclipse 常用快捷键
- runlevel