iOS 数据库
来源:互联网 发布:电影机智问答知乎 编辑:程序博客网 时间:2024/06/01 10:32
ios中常用的数据是sqlite,常见的编辑器是lita
新建数据库DishOrder,两张表一张是Category,一张是Dish表。
Category表中,一个是Categoryid,一个是CategoryTitle.
Dish表中,Dishid,DishTitle,DishWeight,DishPrice,Categoryid
把数据库文件加入前一个工程。下载FMDB库。
https://github.com/ccgus/fmdb
删除FMDB.m文件。添加FrameWork
libsqlite3.dylib
TableViewController添加成员变量
NSMutableArray *_items;
修改TableViewController.m
- (void)viewDidLoad
{
[superviewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
//self.tableView.rowHeight=80;
self.title=@"首页";
_items=[[NSMutableArrayalloc]init];
FMDatabase *db=[FMDatabasedatabaseWithPath:[[NSBundlemainBundle]pathForResource:@"DishOrder"ofType:@"db"]];
if ([dbopen]) {
FMResultSet *fResult =[dbexecuteQuery:@"select * from category"];
while ([fResultnext]) {
NSString *t=[fResultstringForColumn:@"categoryTitle"];
[_itemsaddObject:t];
}
[fResultclose];
}
[dbclose];
}
- (void) viewDidUnload
{
[_itemsrelease];
_items=nil;
[superviewDidUnload];
}
- (void)dealloc
{
[_itemsrelease];
[superdealloc];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return [_itemscount];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
staticNSString *CellIdentifier =@"Cell";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier ];
// Configure the cell...
if (!cell) {
cell=[[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"cell"]autorelease];
}
cell.textLabel.text=[_itemsobjectAtIndex:indexPath.row];
return cell;
}
源码地址:http://download.csdn.net/detail/cloud95/5191785- iOS 数据库
- ios 数据库
- iOS---数据库
- ios数据库
- ios数据库
- ios数据库
- IOS数据库
- iOS 数据库
- ios数据库
- IOS 数据库
- IOS数据库
- iphone ios 数据库操作
- iOS 开发资源 - 数据库
- ios访问sqlite数据库
- iOS持久化(数据库)
- ios 数据库简单操作
- iOS sqlite3 数据库操作
- iOS sqlite数据库
- JEECG_V3.0 码农的福音~
- 设置VirtualBox和主机互相通讯
- Sqlite数据多表联合update
- 一篇关于uilabel的探讨
- Tescom高智能摄像机
- iOS 数据库
- Vxworks及Linux 中常用的延时方法
- 统计单词个数排序输出
- 不能断断续续学android了!
- [UVALive4394]String Painter
- Out of tree builds are impossible with config.h in source dir
- crontab命令详解
- openerp安装一个新模块出的问题Validate Error Error occurred while validating the field(s) arch: Invalid XML for
- wordpress press 找回admin密码,并且固定密码