iOS FMDB增删改查(最简便)

字数 3629阅读 221

用cocoaPods配置第三方文件

第一步。打开终端

第二步。cd+文件夹

第三步。pod init

第四步。打开podfild文件

第五步。pod install 安装第三方






创建Model,LoadData(继承与NSObj)

创建AddViewContorller(继承与UIViewController  绑定XIB)

创建UpDataViewController(继承与UIViewController  绑定XIB)

创建MyTableViewCell(继承与UITableViewCell)

创建YanzhengViewController(继承与UIViewController)

————————————————————————

在Model.h 里写

@property(nonatomic,strong)NSString * home,*price,*kind,*sett,*bz;

@property(nonatomic,assign)NSInteger ID;

————————————————————————

在LoadData.h里写

#import#import "Model.h"

@interface LoadData : NSObject

//单例

+(LoadData *)shareData;

//添加数据

-(void)insertDate:(Model *)insert;

//删除数据

-(void)deleteData:(Model *)dele;

//修改数据

-(void)updateData :(Model *)updata;

//查询数据

-(NSMutableArray *)selct;

————————————————————————

在LoadData.m里写

#import "LoadData.h"#importstatic LoadData * ld = nil;

static FMDatabase * base;

@implementation LoadData

//单例

+(LoadData *)shareData{

static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{

ld = [[LoadData alloc]init];

[ld initData];

});

return ld;

}

+(instancetype)allocWithZone:(struct _NSZone *)zone{

static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{

ld = [super allocWithZone:zone];

});

return ld;

}

-(id)copy{

return self;

}

-(id)mutableCopy{

return self;

}

-(void)initData{

NSString * path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];

NSString * newpath = [path stringByAppendingPathComponent:@"pp.sqlite"];

base = [[FMDatabase alloc]initWithPath:newpath];

if ([base open]) {

[base executeUpdate:@"create table class (ID integer primary key ,home text,price text,kind text,sett text,bz text)"];

}else{

NSLog(@"创建失败");

}

[base close];

}

//添加数据

-(void)insertDate:(Model *)insert{

if ([base open]) {

[base executeUpdate:[NSString stringWithFormat:@"insert into class values (null , '%@', '%@', '%@', '%@', '%@')",insert.home,insert.price,insert.kind,insert.sett,insert.bz]];

}else{

NSLog(@"添加失败");

}

[base close];

}

//删除数据

-(void)deleteData:(Model *)dele{

if ([base open]) {

[base executeUpdate:[NSString stringWithFormat:@"delete from class where ID = '%ld'",dele.ID]];

}else{

NSLog(@"删除失败");

}

[base close];

}

//修改数据

-(void)updateData :(Model *)updata{

if ([base open]) {

[base executeUpdate:[NSString stringWithFormat:@"update class set home = '%@',price = '%@',kind = '%@',sett = '%@',bz = '%@' where ID = '%ld'",updata.home,updata.price,updata.kind,updata.sett,updata.bz,updata.ID]];

}else{

NSLog(@"修改失败");

}

[base close];

}

//查询数据

-(NSMutableArray *)selct{

NSMutableArray * arr = [[NSMutableArray alloc]init];

[base open];

FMResultSet * set = [[FMResultSet alloc]init];

set = [base executeQuery:@"select * from class"];

while ([set next]) {

Model * model = [[Model alloc]init];

model.ID = [set intForColumn:@"ID"];

model.home = [set stringForColumn:@"home"];

model.price = [set stringForColumn:@"price"];

model.kind = [set stringForColumn:@"kind"];

model.sett = [set stringForColumn:@"sett"];

model.bz = [set stringForColumn:@"bz"];

[arr addObject:model];

}

[base close];

return arr;

}

————————————————————————

在AppDele.m 里写

YanZhengViewController * view = [[YanZhengViewController alloc]init];

UINavigationController * nqv = [[UINavigationController alloc]initWithRootViewController:view];

self.window.rootViewController = nqv;

————————————————————————

在AddViewController.m里写

(xib拖拽)


#import "AddViewController.h"

#import "Model.h"

#import "LoadData.h"

@interface AddViewController ()

@property (weak, nonatomic) IBOutlet UITextField *tf;

@property (weak, nonatomic) IBOutlet UITextField *tf1;

@property (weak, nonatomic) IBOutlet UITextField *tf2;

@property (weak, nonatomic) IBOutlet UITextField *tf3;

@property (weak, nonatomic) IBOutlet UITextField *tf4;

@end

@implementation AddViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view from its nib.

}

- (IBAction)btn:(id)sender {

//赋值

Model * model = [[Model alloc]init];

model.home = self.tf.text;

model.price = self.tf1.text;

model.kind = self.tf2.text;

model.sett = self.tf3.text;

model.bz = self.tf4.text;

[[LoadData shareData]insertDate:model];

[self.navigationController popViewControllerAnimated:YES];

}

——————————————————————

在MyTableViewCell.h里写

@property(nonatomic,strong)UILabel * homeLable,*priceLable,*kindLable,*setLable,*bzLable;

————————————————————————

在MyTableViewCell.m里写

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

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

[self.contentView addSubview:self.homeLable];

[self.contentView addSubview:self.priceLable];

[self.contentView addSubview:self.kindLable];

[self.contentView addSubview:self.setLable];

[self.contentView addSubview:self.bzLable];

}

return self;

}

-(UILabel *)homeLable{

if (!_homeLable) {

_homeLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 5, 60, 30)];

}

return _homeLable;

}

-(UILabel *)priceLable{

if (!_priceLable) {

_priceLable = [[UILabel alloc]initWithFrame:CGRectMake(60, 5, 60, 30)];

}

return _priceLable;

}

-(UILabel *)kindLable{

if (!_kindLable) {

_kindLable = [[UILabel alloc]initWithFrame:CGRectMake(120, 5, 60, 30)];

}

return _kindLable;

}

-(UILabel *)setLable{

if (!_setLable) {

_setLable = [[UILabel alloc]initWithFrame:CGRectMake(180, 5, 60, 30)];

}

return _setLable;

}

-(UILabel *)bzLable{

if (!_bzLable) {

_bzLable = [[UILabel alloc]initWithFrame:CGRectMake(240, 5, 60, 30)];

}

return _bzLable;

}

————————————————————————

在UpdataViewController.h里写

#import#import "Model.h"

@interface UpdataViewController : UIViewController

@property(nonatomic,strong)Model * model;

@end

————————————————————————

在UpdataViewController.m里写(用XIB拖拽)



#import "UpdataViewController.h"

#import "Model.h"

#import "LoadData.h"

@interface UpdataViewController ()

@property (weak, nonatomic) IBOutlet UITextField *tf;

@property (weak, nonatomic) IBOutlet UITextField *tf1;

@property (weak, nonatomic) IBOutlet UITextField *tf2;

@property (weak, nonatomic) IBOutlet UITextField *tf3;

@property (weak, nonatomic) IBOutlet UITextField *tf4;

@end

@implementation UpdataViewController

- (void)viewDidLoad {

[super viewDidLoad];

//接收model里面的值

self.tf.text = self.model.home;

self.tf1.text = self.model.price;

self.tf2.text = self.model.kind;

self.tf3.text = self.model.sett;

self.tf4.text = self.model.bz;

}

- (IBAction)btn:(id)sender {

Model * mm = self.model;

mm.home = self.tf.text;

mm.price= self.tf1.text;

mm.kind = self.tf2.text;

mm.sett = self.tf3.text;

mm.bz = self.tf4.text;

[[LoadData shareData]updateData:mm];

[self.navigationController popViewControllerAnimated:YES];

}

————————————————————————

ViewController.m里写

#import "ViewController.h"#import "LoadData.h"#import "Model.h"#import "MyTableViewCell.h"#import "UpdataViewController.h"#import "AddViewController.h"@interface ViewController (){

UITableView * _table;

NSMutableArray * Marr;

}

@end

@implementation ViewController

//将要执行

-(void)viewWillAppear:(BOOL)animated{

//数组接受所有数据

Marr= [[LoadData shareData]selct];

//刷新

[_table reloadData];

}

- (void)viewDidLoad {

[super viewDidLoad];

//定义表格

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

_table.delegate = self;

_table.dataSource = self;

[self.view addSubview:_table];

//添加导航按钮

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

self.navigationItem.rightBarButtonItem = right;

}

//实现点击方法

-(void)click{

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

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

}

//确定行数

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

return Marr.count;

}

//确定内容

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

NSString * str = @"o";

MyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:str];

if (!cell) {

cell = [[MyTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str];

}

Model * model= Marr[indexPath.row];

cell.homeLable.text = model.home;

cell.priceLable.text = model.price;

cell.kindLable.text = model.kind;

cell.setLable.text = model.sett;

cell.bzLable.text = model.bz;

return cell;

}

//实现删除方法

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

Model * model = Marr[indexPath.row];

[[LoadData shareData]deleteData:model];

[Marr removeObjectAtIndex:indexPath.row];

[_table reloadData];

}

//点击跳入修改界面

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

UpdataViewController * update = [[UpdataViewController alloc]init];

update.model = Marr[indexPath.row];

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

}

————————————————————————

YanZhengViewController.m里写

#import "YanZhengViewController.h"

#import "ViewController.h"

@interface YanZhengViewController (){

UITextField * text;

UIButton * btn;

}

@end

@implementation YanZhengViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.navigationController.title = @"物流管理系统";

self.view.backgroundColor= [UIColor whiteColor];

text = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 45)];

text.placeholder =@"请输入手机号码";

[self.view addSubview:text];

btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 200, 200, 45)];

[btn setTitle:@"验证" forState:UIControlStateNormal];

btn.backgroundColor = [UIColor blueColor];

[btn addTarget:self action:@selector(press) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:btn];

}

-(void)press{

NSString *checkString = text.text;

// 1.创建正则表达式,

//NSString *pattern = @"^\\d{14}[[0-9],0-9xX]$";

NSString *pattern = @"^((13[0-9])|(15[^4,4\\D])|(18[0-9])|(14[57])|(17[013678]))\\d{8}$";

// 1.1将正则表达式设置为OC规则

NSPredicate * preURL =[NSPredicate predicateWithFormat:@"self matches%@",pattern ];

bool b1 = [preURL evaluateWithObject:checkString];

if (b1) {

NSLog(@"手机号验证正确");

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

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

}else{

NSLog(@"手机号验证不正确");

}

}

求赏。

-------------------------------------------------------------------


创建LoadData和Model(继承与NSOBj)

创建MyTableViewCell(继承与UITableViewCell)

创建OneViewController(继承与UIViewController)

————————————————————————————————————————

在Appdele.h中

#import <uikit>

#import <Coredata>

@interface AppDelegate : UIResponder@property (strong, nonatomic) UIWindow *window;

@property (readonly, strong) NSPersistentContainer *persistentContainer;

- (void)saveContext;

@end

————————————————————————————————————————

在Appdele.m中

//初始化

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

//导航控制器

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

//添加到试图

self.window.rootViewController = nvc;

return YES;

______________________________________________________________________________________

Loaddata.h

#import <FMDBbase>

#import "Model.h"

//定义单列类

+(instancetype)shearLoadData;

//添加属性

-(void)AddshearLoadData:(Model *)mm;

//查询

-(NSMutableArray *)updateshearLoadData;

____________________________________________________________________________________

load data.m

#import "LoadData.h"

static LoadData *ld = nil;

static FMDatabase *fmdb;

@implementation LoadData

//定义单列类

+(instancetype)shearLoadData{

//初始化

static dispatch_once_t oneefet;

//添加

dispatch_once(&oneefet, ^{

//初始化

ld = [[LoadData alloc]init];

[ld initA];

});

//返回值

return ld;

}

+(instancetype)allocWithZone:(struct _NSZone *)zone{

//判断

if (!ld) {

ld= [super allocWithZone:zone];

}

return ld;

}

//浅复制

-(id)copy{

return self;

}

//深复制

-(id)mutableCopy{

return self;

}

-(void)initA{

//初始化

NSString *str = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];

//添加到

NSString *path = [str stringByAppendingPathComponent:@"lll.sqlite"];

//添加到fmdb

fmdb = [[FMDatabase alloc]initWithPath:path];

//判断

if ([fmdb open]) {

//创建语句

[fmdb executeUpdate:@"create table class (ID integer primary key , name text , age text , QQ text , sj text ,wx text )"];

//关闭

[fmdb close];

NSLog(@"成功");

}else{

NSLog(@"失败");

}

}

//添加属性

-(void)AddshearLoadData:(Model *)mm{

//开始

[fmdb open];

//定义字符串

NSString *str = [NSString stringWithFormat:@"insert into class values (null , '%@','%@','%@','%@','%@')",mm.name,mm.age,mm.QQ,mm.sj,mm.wx];

//使用bool值接受

BOOL ii = [fmdb executeUpdate:str];

//判断

if (ii) {

NSLog(@"成功");

}else{

NSLog(@"失败");

}

//关闭

[fmdb close];

}

//查询

-(NSMutableArray *)updateshearLoadData{

//初始化数组

NSMutableArray *arr = [NSMutableArray new];

//开始

[fmdb open];

//初始化

FMResultSet *Set = [[FMResultSet alloc]init];

//添加

Set = [fmdb executeQuery:@"select *from class"];

//判断

while ([Set next]) {

//初始化

Model *mm = [Model new];

//取值

mm.name = [Set stringForColumn:@"name"];

mm.age = [Set stringForColumn:@"age"];

mm.QQ = [Set stringForColumn:@"QQ"];

mm.sj = [Set stringForColumn:@"sj"];

mm.wx = [Set stringForColumn:@"wx"];

mm.ID = [Set intForColumn:@"ID"];

//添加到数组

[arr addObject:mm];

}

//返回值

return arr;

}

——————————————————————————————————————

model.h

@property (nonatomic , strong) NSString *name;

@property (nonatomic , strong) NSString *age;

@property (nonatomic , strong) NSString *QQ;

@property (nonatomic , strong) NSString *sj;

@property (nonatomic , strong) NSString *wx;

@property (nonatomic , assign) NSInteger ID;

__________________________________________________________________________________

MyTableViewCell.h

@property (nonatomic , strong) UILabel *name;

@property (nonatomic , strong) UILabel *age;

@property (nonatomic , strong) UILabel *QQ;

@property (nonatomic , strong) UILabel *sj;

@property (nonatomic , strong) UILabel *wx;

_______________________________________________________________________________

MyTableViewCell.m

//重写父类方法

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

//判断

if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier] ) {

//添加

[self.contentView addSubview:self.name];

[self.contentView addSubview:self.age];

[self.contentView addSubview:self.QQ];

[self.contentView addSubview:self.sj];

[self.contentView addSubview:self.wx];

}

//返回值

return self;

}

//懒加载

-(UILabel *)name{

//判断

if (!_name) {

//初始化

_name = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 90, 50)];

}

return _name;

}

//懒加载

-(UILabel *)age{

//判断

if (!_age) {

//初始化

_age = [[UILabel alloc]initWithFrame:CGRectMake(100, 0, 90, 50)];

}

return _age;

}

//懒加载

-(UILabel *)QQ{

//判断

if (!_QQ) {

//初始化

_QQ = [[UILabel alloc]initWithFrame:CGRectMake(160, 0, 90, 50)];

}

return _QQ;

}

//懒加载

-(UILabel *)sj{

//判断

if (!_sj) {

//初始化

_sj = [[UILabel alloc]initWithFrame:CGRectMake(220, 0, 90, 50)];

}

return _sj;

}

//懒加载

-(UILabel *)wx{

//判断

if (!_wx) {

//初始化

_wx = [[UILabel alloc]initWithFrame:CGRectMake(280, 0, 90, 50)];

}

return _wx;

}

___________________________________________________________________________________

OneViewController.m

#import "OneViewController.h"

#import "MyTableViewCell.h"

#import "Model.h"#

import "LoadData.h"

@interface OneViewController (){

UITableView *table;

NSMutableArray *marr;

}

//将要发生的

-(void)viewWillAppear:(BOOL)animated{

//使用数组接受

marr = [[LoadData shearLoadData]updateshearLoadData];

//刷新

[table reloadData];

}

- (void)viewDidLoad {

[super viewDidLoad];

//定义背景颜色

self.view.backgroundColor = [UIColor whiteColor];

//初始化

table = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];

//添加协议

table.delegate = self;

table.dataSource  = self;

//添加到试图

[self.view addSubview:table];

//定导航按钮

UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithTitle:@"横屏" style:UIBarButtonItemStyleDone target:self action:@selector(click1)];

//定义位置

UIBarButtonItem *right2 = [[UIBarButtonItem alloc]initWithTitle:@"竖屏" style:UIBarButtonItemStyleDone target:self action:@selector(click2)];

//定义位置

self.navigationItem.rightBarButtonItems = @[right,right2];

}

//定义行数

-(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.name.text = mm.name;

cell.age.text = mm.age;

cell.QQ.text = mm.QQ;

cell.sj.text = mm.sj;

cell.wx.text = mm.wx;

//返回值

return cell;

}

-(void)click1{

[self interfaceOrientation:UIInterfaceOrientationLandscapeRight];

}

-(void)click2{

[self interfaceOrientation:UIInterfaceOrientationPortrait];

}

- (void)interfaceOrientation:(UIInterfaceOrientation)orientation

{

if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {

SEL selector            = NSSelectorFromString(@"setOrientation:");

NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];

[invocation setSelector:selector];

[invocation setTarget:[UIDevice currentDevice]];

int val                  = orientation;

[invocation setArgument:&val atIndex:2];

[invocation invoke];

}

}

—————————————————————————————————————————

view.m

#import "Model.h"

#import "LoadData.h"

#import "OneViewController.h"

@property (nonatomic , strong) UITextField *text1;

@property (nonatomic , strong) UITextField *text2;

@property (nonatomic , strong) UITextField *text3;

@property (nonatomic , strong) UITextField *text4;

@property (nonatomic , strong) UITextField *text5;

@property (nonatomic , strong) UILabel *label1;

@property (nonatomic , strong) UILabel *label2;

@property (nonatomic , strong) UILabel *label3;

@property (nonatomic , strong) UILabel *label4;

@property (nonatomic , strong) UILabel *label5;


- (void)viewDidLoad {

[super viewDidLoad];

//导航标题

self.title = @"请输入资料";

//背景颜色

self.view.backgroundColor = [UIColor whiteColor];

//开始

[self kaishi];

//输入框

[self biaokuang];

//定义按钮

UIButton *but = [UIButton buttonWithType:UIButtonTypeRoundedRect];

//定义位置

but.frame = CGRectMake(100, 450, 100, 44);

//定义文字

[but setTitle:@"保存" forState:0];

//定义背景颜色

but.backgroundColor = [UIColor lightGrayColor];

//定义文字颜色

[but setTitleColor:[UIColor blueColor] forState:0];

//添加事件

[but addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];

//添加到试图

[self.view addSubview:but];

//定导航按钮

UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithTitle:@"查看全部" style:UIBarButtonItemStyleDone target:self action:@selector(click1)];

//定义位置

self.navigationItem.rightBarButtonItem = right;

}

-(void)kaishi{

//初始化

_label1 = [[UILabel alloc]initWithFrame:CGRectMake(30, 70, 50, 50)];

//文字

_label1.text = @"姓名";

//居中

_label1.textAlignment = NSTextAlignmentCenter;

//添加到试图

[self.view addSubview:_label1];

//初始化

_label2 = [[UILabel alloc]initWithFrame:CGRectMake(30, 150, 50, 50)];

//文字

_label2.text = @"年龄";

//居中

_label2.textAlignment = NSTextAlignmentCenter;

//添加到试图

[self.view addSubview:_label2];

//初始化

_label3 = [[UILabel alloc]initWithFrame:CGRectMake(30, 225, 50, 50)];

//文字

_label3.text = @"QQ";

//居中

_label3.textAlignment = NSTextAlignmentCenter;

//添加到试图

[self.view addSubview:_label3];

//初始化

_label4 = [[UILabel alloc]initWithFrame:CGRectMake(30, 300, 50, 50)];

//文字

_label4.text = @"手机";

//居中

_label4.textAlignment = NSTextAlignmentCenter;

//添加到试图

[self.view addSubview:_label4];

//初始化

_label5 = [[UILabel alloc]initWithFrame:CGRectMake(30, 375, 50, 50)];

//文字

_label5.text = @"微信";

//居中

_label5.textAlignment = NSTextAlignmentCenter;

//添加到试图

[self.view addSubview:_label5];

}

-(void)biaokuang{

//初始化

_text1 = [[UITextField alloc]initWithFrame:CGRectMake(100, 75, 200, 50)];

//居中

_text1.textAlignment = NSTextAlignmentCenter;

//设置边框

[_text1 setBorderStyle:UITextBorderStyleRoundedRect];

_text1.layer.borderWidth= 1.0f;

//添加到试图

[self.view addSubview:_text1];

//初始化

_text2 = [[UITextField alloc]initWithFrame:CGRectMake(100, 150, 200, 50)];

//居中

_text2.textAlignment = NSTextAlignmentCenter;

//设置边框

[_text2 setBorderStyle:UITextBorderStyleRoundedRect];

_text2.layer.borderWidth= 1.0f;

//添加到试图

[self.view addSubview:_text2];

//初始化

_text3 = [[UITextField alloc]initWithFrame:CGRectMake(100, 225, 200, 50)];

//设置边框

[_text3 setBorderStyle:UITextBorderStyleRoundedRect];

_text3.layer.borderWidth= 1.0f;

//居中

_text3.textAlignment = NSTextAlignmentCenter;

//添加到试图

[self.view addSubview:_text3];

//初始化

_text4 = [[UITextField alloc]initWithFrame:CGRectMake(100, 300, 200, 50)];

//设置边框

[_text4 setBorderStyle:UITextBorderStyleRoundedRect];

_text4.layer.borderWidth= 1.0f;

//居中

_text4.textAlignment = NSTextAlignmentCenter;

//添加到试图

[self.view addSubview:_text4];

//初始化

_text5 = [[UITextField alloc]initWithFrame:CGRectMake(100, 375, 200, 50)];

//设置边框

[_text5 setBorderStyle:UITextBorderStyleRoundedRect];

_text5.layer.borderWidth= 1.0f;

//居中

_text5.textAlignment = NSTextAlignmentCenter;

//添加到试图

[self.view addSubview:_text5];

}

-(void)click{

//初始化

Model *mm = [Model new];

//添加修

mm.name = _text1.text;

mm.age = _text2.text;

mm.QQ = _text3.text;

mm.sj = _text4.text;

mm.wx = _text5.text;

//添加到

[[LoadData shearLoadData]AddshearLoadData:mm];

}

-(void)click1{

//初始化

OneViewController *one = [[OneViewController alloc]init];

//跳转

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

}

推荐阅读更多精彩内容