FMDB Model

2017-06-30  本文已影响11人  黑市掌柜

配置cocoaPods配置第三方文件

第一步。打开终端

第二步。cd+文件夹

第三步。pod init

第四步。打开podfild文件

第五步。pod install 安装第三方

展示界面oneviewcontroll:

#import "OneViewController.h"

#import "FMDateFiction.h"

#import "FMDateFictionModel.h"

#import "tianjiaViewController.h"

#import "xiugaiViewController.h"

{

UITableView *theTable;

NSArray *theArr;

}

-(void)viewWillAppear:(BOOL)animated

{

theArr = [[FMDateFiction sharedFM]getAll];

[theTable reloadData];

}

- (void)viewDidLoad {

[super viewDidLoad];

self.view.backgroundColor = [UIColor whiteColor];

theTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)style:UITableViewStyleGrouped];

theTable.delegate = self;

theTable.dataSource =self;

theTable.rowHeight = 80;

[self.view addSubview:theTable];

self.navigationItem.title = @"物流信息";

UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"添加" style:UIBarButtonItemStylePlain target:self action:@selector(onClickedOKbtn)];

self.navigationItem.rightBarButtonItem = rightBarItem;

}

-(void)onClickedOKbtn

{

NSLog(@"添加");

tianjiaViewController *theT = [[tianjiaViewController alloc]init];

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

}

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

{

return theArr.count;

}

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

{

static NSString *Str = @"Cell";

UITableViewCell *theTVC = [tableView dequeueReusableCellWithIdentifier:Str];

if (!theTVC) {

theTVC = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];

}

FMDateFictionModel *theModel = theArr[indexPath.row];

NSString *ss = [NSString stringWithFormat:@"类型:%@  收人:%@  手机号:%@",theModel.theFenglei,theModel.theShouHuoRen,theModel.theDianHua];

theTVC.textLabel.text =ss;

NSString *theSS = [NSString stringWithFormat:@"收获地址:%@    备注:%@",theModel.theDiZhi,theModel.theBeiZhu];

theTVC.detailTextLabel.text = theSS;

return theTVC;

}

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

{

FMDateFictionModel *m = [theArr objectAtIndex:indexPath.row];

[[FMDateFiction sharedFM]deleteMusic:m];

theArr = [[FMDateFiction sharedFM]getAll];

[theTable reloadData];

}

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

{

xiugaiViewController *theXG = [[xiugaiViewController alloc]init];

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

}

在ViewControll里:

tianjiaViewController:

self.view.backgroundColor = [UIColor whiteColor];

theYoujian = [[UITextField alloc]initWithFrame:CGRectMake(50, 100, self.view.frame.size.width-100, 40)];

theYoujian.backgroundColor = [UIColor greenColor];

theYoujian.placeholder = @"型";

[self.view addSubview:theYoujian];

thedizhi = [[UITextField alloc]initWithFrame:CGRectMake(50, 150, self.view.frame.size.width-100, 40)];

thedizhi.backgroundColor = [UIColor greenColor];

thedizhi.placeholder = @"收";

[self.view addSubview:thedizhi];

theshouren = [[UITextField alloc]initWithFrame:CGRectMake(50, 200, self.view.frame.size.width-100, 40)];

theshouren.backgroundColor = [UIColor greenColor];

theshouren.placeholder = @"人";

[self.view addSubview:theshouren];

thedianhua = [[UITextField alloc]initWithFrame:CGRectMake(50, 250, self.view.frame.size.width-100, 40)];

thedianhua.backgroundColor = [UIColor greenColor];

thedianhua.placeholder = @"话";

[self.view addSubview:thedianhua];

thebeizhu = [[UITextField alloc]initWithFrame:CGRectMake(50, 300, self.view.frame.size.width-100, 40)];

thebeizhu.backgroundColor = [UIColor greenColor];

thebeizhu.placeholder = @"注";

[self.view addSubview:thebeizhu];

UIButton *theyanzheng = [[UIButton alloc]initWithFrame:CGRectMake(100, 350, self.view.frame.size.width-200, 40)];

theyanzheng.backgroundColor = [UIColor redColor];

[theyanzheng setTitle:@"添加" forState:UIControlStateNormal];

[theyanzheng addTarget:self action:@selector(tianjia) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:theyanzheng];

}

-(void)tianjia

{

FMDateFictionModel *theModel = [[FMDateFictionModel alloc]init];

theModel.theFenglei = theYoujian.text;

theModel.theShouHuoRen = theshouren.text;

theModel.theDiZhi = thedizhi.text;

theModel.theDianHua = thedianhua.text;

theModel.theBeiZhu = thebeizhu.text;

[[FMDateFiction sharedFM]insertMusic:theModel];

[self.navigationController popViewControllerAnimated:NO];

}

xiugaiViewController里:

FMDateFictionModel.h里:

FMDateFictionModel.m里

FMDateFictionmodel.h里:

上一篇下一篇

猜你喜欢

热点阅读