iOS 数据库

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 ([db open]) {

       FMResultSet *fResult =[db executeQuery:@"select * from category"];

       while ([fResult next]) {

           NSString *t=[fResult stringForColumn:@"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

{

   static NSString *CellIdentifier =@"Cell";

   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值