导入第三方FMDB
//AppDelegate.m
#import "ViewController.h"
//初始化
ViewController *vc = [[ViewController alloc]init];
//导航控制器
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"
//协议
<UITableViewDelegate,UITableViewDataSource>
//全局变量
{
UITableView *tabele;
NSMutableArray *marr;
}
//将要显示
-(void)viewWillAppear:(BOOL)animated{
//查询
marr = [[LoadData sharlLoadData]Marr];
//刷新
[tabele reloadData ];
}
==========viewDidLoad
//定义标题
self.title = @"租房信息查询系统";
//初始化
tabele = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
//添加协议
tabele.delegate = self;
tabele.dataSource = self;
//添加到试图上
[self.view addSubview:tabele];
//定义按钮
UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithTitle:@"添加" style:UIBarButtonItemStylePlain target:self action:@selector(click)];
//添加到导航调试
self.navigationItem.rightBarButtonItem = right;
=================
-(void)click{
//初始化
AddViewController *add = [AddViewController new];
//跳转
[self.navigationController pushViewController:add animated:YES];
}
//行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return marr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//初始化
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@""];
//复用池
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];
}
//跳转
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//初始化
UpViewController *up = [UpViewController new];
//添加
up.mm = marr[indexPath.row];
//修改
[[LoadData sharlLoadData]UPsharlLoadData:up.mm];
//跳转
[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];
//跳转
[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
//将数据添加到修改页面
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];
//跳转
[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;
网友评论