本人菜鸟一枚,今天就和大家分享分享fmdb的使用和一些中间出现的问题:欢迎大家来互相交流指教,废话少说,直接进入主题吧:————————————————————>
使用Fmdb的首先要把第三方文件上传到工程中;
在就是在依赖库中添加libsqlite3.tdb库文件;
👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇下面就是代码了:
创建自己的model类用于存储暂时的数据用于进行增,删,改,查;
这里就不展示了;
创建数据库,运用sql语句进行增删改查;

其中还有一个就是常见的单例,相信只要入行的人士都会对单例有或多或少的理解吧,这里就不进行详解了,有事问度娘吧,其实我也是刚入行也说不出个一二三来🤔🤔;


下面是进行增删改查方法的具体实现部分了;



上面的文件可以在一个一面中进行;
下面是要在viewcontoller页面中进行码字了;
要进行数据的展示,要创建个表格;
这也不进行展示了;
下面就来展示下载表格代理中的一些方法的调动进行增删改查;
先来点效果图便于大家理解

这里用到表格代理中的点击单元格和进行删除单元格的方法;
看一下代码呀:;;
//设置点击单元格的方法;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//获得点击单元格的model类;
student *s=muarr[indexPath.row];
//设置页面的跳转;
updateViewController *up=[[updateViewController alloc]init];
s.stuid=indexPath.row;
up.mystu=s;
[self.navigationController pushViewController:up animated:YES];
}
//设置删除的方法;
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
//获取要删除的model
student *my=muarr[indexPath.row];
//从数组中删除;
[muarr removeObject:my];
//调用方法从数据库删除;
[[LoadData shareLoadData]deleteData:my];
//进行刷新;
[thetab reloadData];
}
对了忘了讲了上面最重要的是在表格创建之前进行查询数据,然后再在表格上进行展示;
下面是更改数据和添加数据的代码实现了,这里我是另创建了俩界面进行布局;


这里再附上点代码吧,怕新手们迷茫呀😎😎😎


我的理解就这些了,希望对大家有帮助,,如有不好处请大家进行指教。
网友评论