FMDB(ZHY)

//ViewController代碼(model數(shù)據(jù)以及FMDB包沒有上傳)

#import "ViewController.h"

#import "Model.h"

#import "FMDBdatabase.h"

#import "AddViewController.h"

#import "XiuGaiViewController.h"

@interface ViewController (){

NSMutableArray *Marr;

}

@property(nonatomic,strong)UITableView *table;

@end

@implementation ViewController

-(void)viewWillAppear:(BOOL)animated

{

Marr = [[FMDBdatabase danli]Marr];

[self.table reloadData];

}

- (void)viewDidLoad {

[super viewDidLoad];

[self.view addSubview:self.table];

UIBarButtonItem *butt =[[UIBarButtonItem alloc]initWithTitle:@"ADD" style:UIBarButtonItemStylePlain target:self action:@selector(Add)];

self.navigationItem.rightBarButtonItem = butt;

}

-(void)Add{

AddViewController *aa =[[AddViewController alloc]init];

[self.navigationController pushViewController:aa animated:NO];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return? Marr.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *cellID =@"cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

if (!cell)

{

cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];

}

Model *mm =[Marr objectAtIndex:indexPath.row];

cell.textLabel.text = [NSString stringWithFormat:@"%@",mm.name];

cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",mm.age];

return cell;

}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

Model *mm = [Marr objectAtIndex:indexPath.row];

[[FMDBdatabase danli]deletedata:mm];

[Marr removeObjectAtIndex:indexPath.row];

[self.table reloadData];

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

XiuGaiViewController * up = [[XiuGaiViewController alloc]init];

up.mm = Marr[indexPath.row];

[self.navigationController pushViewController:up animated:YES];

}

-(UITableView *)table{

if (!_table)

{_table = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];

_table.delegate = self;

_table.dataSource = self;

}

return? _table;

}

//數(shù)據(jù)添加

Model *mm? =[[Model alloc]init];

mm.name = self.nameText.text;

mm.age = self.ageText.text;

[[FMDBdatabase danli]inserdata:mm];


//修改界面的代碼實現(xiàn)修改功能

在.h中定義

@property(nonatomic,strong)Model *mm;

//在.m 中調(diào)用代碼

- (void)viewDidLoad {

[super viewDidLoad];

self.xiutext.text = self.mm.name;

self.xiuage.text = self.mm.age;

}

- (IBAction)button:(id)sender {

Model *mm =self.mm;

mm.name = self.xiutext.text;

mm.age = self.xiuage.text;

[[FMDBdatabase danli]updata:mm];

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容