數(shù)據(jù)庫1完善

導(dǎo)入第三方FMDB


//AppDelegate.m

#import "ViewController.h"

//初始化

ViewController *vc = [[ViewController alloc]init];

//導(dǎo)航控制器

UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:vc];

//添加圖

self.window.rootViewController = nvc;



//? ViewController.m 繼承UIViewController

#import "LoadData.h"

#import "Model.h"

#import "MyTableViewCell.h"

#import "UpViewController.h"

#import "AddViewController.h"

//協(xié)議

<UITableViewDelegate,UITableViewDataSource>

//全局變量

{

UITableView *tabele;

NSMutableArray *marr;

}


//將要顯示

-(void)viewWillAppear:(BOOL)animated{

//查詢

marr = [[LoadData sharlLoadData]Marr];

//刷新

[tabele reloadData ];

}

==========viewDidLoad

//定義標(biāo)題

self.title = @"租房信息查詢系統(tǒng)";

//初始化

tabele = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];

//添加協(xié)議

tabele.delegate = self;

tabele.dataSource = self;

//添加到試圖上

[self.view addSubview:tabele];

//定義按鈕

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

//添加到導(dǎo)航調(diào)試

self.navigationItem.rightBarButtonItem = right;

=================

-(void)click{

//初始化

AddViewController *add = [AddViewController new];

//跳轉(zhuǎn)

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

}

//行數(shù)

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

return marr.count;

}

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

//初始化

MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@""];

//復(fù)用池

if (!cell) {

//初始化‘

cell = [[MyTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@""];

}

//初始化

Model *mm = marr[indexPath.row];

//添加到表格上

cell.fw.text = mm.fw;

cell.zj.text = mm.zj;

cell.fh.text = mm.fh;

cell.xs.text = mm.xs;

cell.bz.text = mm.bz;

//返回值

return cell;

}

//刪除

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

//添加

Model *mm? = marr[ indexPath.row];

//刪除

[[LoadData sharlLoadData]deleteharlLoadData:mm];

[marr removeObjectAtIndex:indexPath.row];

//刷新

[tabele reloadData];

}

//跳轉(zhuǎn)

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

//初始化

UpViewController *up = [UpViewController new];

//添加

up.mm = marr[indexPath.row];

//修改

[[LoadData sharlLoadData]UPsharlLoadData:up.mm];

//跳轉(zhuǎn)

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

}



AddViewController.m ? ? Xib文件

//頭文件

#import "Model.h"

#import "LoadData.h"

//拖拽屬性

@property (strong, nonatomic) IBOutlet UITextField *fw;

@property (strong, nonatomic) IBOutlet UITextField *zj;

@property (strong, nonatomic) IBOutlet UITextField *hx;

@property (strong, nonatomic) IBOutlet UITextField *xs;

@property (strong, nonatomic) IBOutlet UITextField *bz;

//方法外拖拽屬性

- (IBAction)sss:(id)sender {

//初始化

Model *mm = [Model new];

//鏈接

mm.fw = self.fw.text;

mm.zj = self.zj.text;

mm.fh = self.hx.text;

mm.xs = self.xs.text;

mm.bz = self.bz.text;

//添加

[[LoadData sharlLoadData]AddsharlLoadData:mm];

//跳轉(zhuǎn)

[self.navigationController popViewControllerAnimated:YES];

}


UpViewController.h

//倒入頭文件

#import "Model.h"

//定義屬性

@property (nonatomic ,strong)Model *mm;


UpViewController.m

#import "LoadData.h"

//拖拽屬性

@property (strong, nonatomic) IBOutlet UITextField *fw;

@property (strong, nonatomic) IBOutlet UITextField *zj;

@property (strong, nonatomic) IBOutlet UITextField *hx;

@property (strong, nonatomic) IBOutlet UITextField *xs;

@property (strong, nonatomic) IBOutlet UITextField *bz;

=========viewDidLoad

//將數(shù)據(jù)添加到修改頁面

self.fw.text = self.mm.fw;

self.zj.text = self.mm.zj;

self.hx.text = self.mm.fh;

self.xs.text = self.mm.xs;

self.bz.text = self.mm.bz;

================

//拖拽按鈕

- (IBAction)ssss:(id)sender {

//初始化

Model *mm = self.mm;

//鏈接

mm.fw = self.fw.text;

mm.zj = self.zj.text;

mm.fh = self.hx.text;

mm.xs = self.xs.text;

mm.bz = self.bz.text;

//添加

[[LoadData sharlLoadData]UPsharlLoadData:mm];

//跳轉(zhuǎn)

[self.navigationController popViewControllerAnimated:YES];

}


//? MyTableViewCell.h??

? 繼承UITableViewCell? 表格重寫類

//定義屬性

@property (nonatomic , strong) UILabel *fw;

@property (nonatomic , strong) UILabel *zj;

@property (nonatomic , strong) UILabel *fh;

@property (nonatomic , strong) UILabel *xs;

@property (nonatomic , strong) UILabel *bz;


//MyTableViewCell.m

//重寫父類方法

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

//判斷

if ([super initWithStyle:style reuseIdentifier:reuseIdentifier])

{

//添加到

[self.contentView addSubview:self.fw];

[self.contentView addSubview:self.zj];

[self.contentView addSubview:self.fh];

[self.contentView addSubview:self.xs];

[self.contentView addSubview:self.bz];

}

//返回值

return self;

}

//懶加載

-(UILabel *)fw{

//判斷

if (!_fw) {

//初始化

_fw = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 80, 44)];

}

//返回值

return _fw;

}

//懶加載

-(UILabel *)zj{

//判斷

if (!_zj) {

//初始化

_zj = [[UILabel alloc]initWithFrame:CGRectMake(80, 5, 80, 44)];

}

//返回值

return _zj;

}

//懶加載

-(UILabel *)fh{

//判斷

if (!_fh) {

//初始化

_fh = [[UILabel alloc]initWithFrame:CGRectMake(155, 5, 80, 44)];

}

//返回值

return _fh;

}

//懶加載

-(UILabel *)xs{

//判斷

if (!_xs) {

//初始化

_xs = [[UILabel alloc]initWithFrame:CGRectMake(220, 5, 80, 44)];

}

//返回值

return _xs;

}

//懶加載

-(UILabel *)bz{

//判斷

if (!_bz) {

//初始化

_bz = [[UILabel alloc]initWithFrame:CGRectMake(305, 5, 80, 44)];

}

//返回值

return _bz;

}


//模型類Model.h

//定義屬性

@property (nonatomic , strong) NSString *fw;

@property (nonatomic , strong) NSString *zj;

@property (nonatomic , strong) NSString *fh;

@property (nonatomic , strong) NSString *xs;

@property (nonatomic , strong) NSString *bz;

//記得nstager assign id

@property (nonatomic , assign) NSInteger ID;

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容