首先把MJExtension 第三方文件拖入到工程里面 Model类和View类里面照常写东西 View里面用xib照常拖

然后在VC.m里面引入#import “AFNetworking/AFNetworking.h”
#import “MJExtension/MJExtension.h”
#import “Model.h” 头文件

主要就是那一行代码

//数组包子店
self.dataSource = [Model mj_objectArrayWithKeyValuesArray:responseObject[@"T1348647853363"]];/* ================  字典包数组==============//        [mjmodel mj_setupObjectClassInArray:^NSDictionary *{//            return   @"类的数组属性":[字典对应的model class ];//        }];*/

接下来是解析部分

-(void)createAFN{

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:@“http://c.m.163.com/nc/article/headline/T1348647853363/0-20.html” parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {

//数组包子店
self.dataSource = [Model mj_objectArrayWithKeyValuesArray:responseObject[@"T1348647853363"]];/* ================  字典包数组==============//        [mjmodel mj_setupObjectClassInArray:^NSDictionary *{//            return   @"类的数组属性":[字典对应的model class ];//        }];*/[self.tbv reloadData];NSLog(@"JSON: %@", responseObject);

} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@“Error: %@”, error);
}];

}

其他部分照常写

                                  FMDB

第一 :
1 把FMDB的第三方拖入到工程里面 创建DataModel 继承NSObject ,这个DataModel里面写的是解析的一些数据 在整个FMDB里面 属于表名 在DataModel里面必须定义一个NSInterger 类型的classID 属于主键ID

@interface DataModel : NSObject

@property(nonatomic,strong)NSString *imgsrc,*title,*mtime,*url;

// 设置一个主键ID
@property(nonatomic , assign)NSInteger classID;

@end

下面是DataModel.m里面的方法:
-(void)setValue:(id)value forUndefinedKey:(NSString *)key{

}

第二:在定义一个Model类 继承于NSObject 在Model类里面主要写了FMDB的一些增,删,改,查
首先在Model.h里面定义一些方法 代码有:

#import <Foundation/Foundation.h>
#import “DataModel.h”
NS_ASSUME_NONNULL_BEGIN

@interface Model : NSObject

//单利方法
+(instancetype)initData;

//初始化数据库
-(void)initSql;
//初始化表格
-(void)initTable;

//添加 从解析里面的数据添加到数据库里面 所以是DataModel
-(void)addData:(DataModel *)data;

//删除
-(void)deletData:(NSInteger )theid;

//查询数据
-(NSMutableArray *)inquireArr;

//关闭数据库
-(void)closeSql;

@end

其次是Model.m里面的实现的一些方法

#import “Model.h”
#import “FMDatabase.h”
//创建静态变量

static Model *sql;
static FMDatabase *db;

@implementation Model

//初始化单利方法

+(instancetype)initData{
if (!sql) {
sql=[[Model alloc]init];

}
return sql;

}

//初始化数据库

-(void)initSql{

//获取Documents目录
NSString *str=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];

//拼接路径
NSString *fileName=[str stringByAppendingString:@“strmb.db”];

NSLog(@"%@",fileName);

//创建数据库
db=[[FMDatabase alloc]initWithPath:fileName];

if ([db open]) {
NSLog(@“打开数据库成功”);

//初始化表格
[self initTable];

}else{

NSLog(@"打开数据库失败");

}

}

//初始化表格
-(void)initTable{
//初始化数据库表格的格式:create table if not exists 表名(主键id integer primary key,所有的数据类型); : 如果不存在DataModel(classID integer primary key,imgsrc blob,title text,url text),则创建表

[db executeUpdate:@“create table if not exists DataModel(classID integer primary key,imgsrc blob,title text,url text,mtime text)”];
//关闭数据库
[db close];

}
//添加数据
-(void)addData:(DataModel *)data{
//添加数据的sql语句:insert into 表名 values(null,?,?);
if ([db open]) {
[db executeUpdate:[NSString stringWithFormat:@“insert into DataModel values(null,’%@’,’%@’,’%@’,’%@’)”,data.imgsrc,data.title,data.url,data.mtime]];
NSLog(@“插入成功”);

}else{
NSLog(@“添加失败”);
}
//关闭数据库
[db close];

}

//删除数据
-(void)deletData:(NSInteger)theid{

if ([db open]) {

  //sql 语句: delete from 表名 where 表名的主键id = ?
[db executeUpdate:[NSString stringWithFormat:@"delete from DataModel where classID=%ld",theid]];
NSLog(@"删除成功");

}else{
NSLog(@“删除失败”);
}
//关闭数据库
[db close];

}
//查询数据库
-(NSMutableArray *)inquireArr{

//创建数据
NSMutableArray *arr=[NSMutableArray new];

//集合
FMResultSet *set=[FMResultSet new];

if ([db open]) {

set=[db executeQuery:@"select *from DataModel"];
//判断有没有东西while ([set next]) {DataModel *model=[[DataModel alloc]init];model.imgsrc=[set stringForColumn:@"imgsrc"];model.title=[set stringForColumn:@"title"];model.url=[set stringForColumn:@"url"];model.mtime = [set stringForColumn:@"mtime"];model.classID=[set intForColumn:@"classID"];[arr addObject:model];}

}else{
NSLog(@“查询失败”);
}
[db close];
return arr;

}

@end

第三:创建TableViewCell继承UITableViewCell 进行拖拽xib约束

其次是拖拽到TableViewCell.h里面

#import <UIKit/UIKit.h>
#import “DataModel.h”
NS_ASSUME_NONNULL_BEGIN

@interface TableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *img;
@property (weak, nonatomic) IBOutlet UILabel *zhu;
@property (weak, nonatomic) IBOutlet UILabel *fu;

-(void)loadData:(DataModel *)mode;

然后在TableViewCell.m里面实现方法

-(void)loadData:(DataModel *)mode{

if (mode) {

self.zhu.text=mode.title;
self.fu.text=mode.mtime;
self.img.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:mode.imgsrc]]];

}

}

第三:是在VC里面进行解析接口添加到表格里面

#import “ViewController.h”
#import <AFNetworking.h>
#import “TableViewCell.h”
#import “DataModel.h”
#import “oneViewController.h”
#import “twoViewController.h”

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tab;
@property(nonatomic,strong)NSMutableArray *DATAsource;

@end

@implementation ViewController

(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.DATAsource=[[NSMutableArray alloc]init];

self.tab=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
self.tab.delegate=self;
self.tab.dataSource=self;
self.navigationItem.title=@“好好学习”;
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@“收藏界面” style:UIBarButtonItemStyleDone target:self action:@selector(click)];

[self.view addSubview:self.tab];
//注册
[self.tab registerNib:[UINib nibWithNibName:@“TableViewCell” bundle:nil] forCellReuseIdentifier:@“cell”];

[self AFN];
}
-(void)click{

twoViewController *two=[twoViewController new];

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

}

-(void)AFN{

AFHTTPSessionManager *manger=[AFHTTPSessionManager manager];

manger.responseSerializer=[AFHTTPResponseSerializer serializer];

[manger GET:@“http://c.m.163.com/nc/article/list/T1348648517839/0-20.html” parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {

} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@“请求成功”);

NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:1 error:nil];NSDictionary *arr=[dic objectForKey:@"T1348648517839"];for (NSDictionary *dic in arr) {DataModel *model=[DataModel new];[model setValuesForKeysWithDictionary:dic];[self.DATAsource addObject:model];}
dispatch_async(dispatch_get_main_queue(), ^{[self.tab reloadData];
});

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

NSLog(@"请求失败");

}];

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

return self.DATAsource.count;

}

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

TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@“cell”];

//
//
// if (cell==nil) {
// cell=[[TableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:oj];
// }

DataModel *model=self.DATAsource[indexPath.row];
self.tab.rowHeight=150;

cell.zhu.text=model.title;
cell.fu.text=model.mtime;
cell.img.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.imgsrc]]];

return cell;

}

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

oneViewController *one=[oneViewController new];

one.model= self.DATAsource[indexPath.row];

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

}

@end

其次创建OneVC

在OneVC.h里面
引入 DataModel.h 进行属性传值

#import <UIKit/UIKit.h>
#import “DataModel.h”
NS_ASSUME_NONNULL_BEGIN

@interface oneViewController : UIViewController
@property(nonatomic,strong)DataModel *model;

@end

其次在OneVC.m里面写 网页视图 点击收藏显示添加成功

#import “oneViewController.h”
#import <WebKit/WebKit.h>
#import “Model.h”

@interface oneViewController ()
@property(nonatomic,strong)WKWebView *webview;
@end

@implementation oneViewController

(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

self.webview=[[WKWebView alloc]initWithFrame:self.view.frame];

self.navigationItem.title=@“网页视图”;
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@“收藏” style:UIBarButtonItemStyleDone target:self action:@selector(click)];

[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.model.url]]]];

[self.view addSubview:self.webview];

}

-(void)click{

[[Model initData]initSql];

[[Model initData]addData:self.model];

}
@end

最后一步创建TwoVC 是收藏的界面 里面显示收藏成功的数据 和一些删除数据的展示 在这里还可以运用自定义cell直接赋值 注册cell

#import “twoViewController.h”
#import “Model.h”
#import “TableViewCell.h”
@interface twoViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tab;
@property(nonatomic,strong)NSMutableArray *arr;

@end

@implementation twoViewController

(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

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

self.tab.delegate=self;
self.tab.dataSource=self;
[self.view addSubview:self.tab];
//注册cell
[self.tab registerNib:[UINib nibWithNibName:@“TableViewCell” bundle:nil] forCellReuseIdentifier:@“cell”];

self.arr=[[NSMutableArray alloc]init];

}

-(void)viewWillAppear:(BOOL)animated{

[[Model initData]initSql];

self.arr=[[Model initData]initeArr];

[self.tab reloadData];

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

return self.arr.count;
1
}

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

static NSString *oj=@“cell”;

TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:oj];

DataModel *model=self.arr[indexPath.row];
self.tab.rowHeight=150;

cell.zhu.text=model.title;
cell.fu.text=model.mtime;
cell.img.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.imgsrc]]];

return cell;

}

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

[[Model initData]initSql];

[[Model initData]deletData:[self.arr[indexPath.row]classID]];

[self.arr removeObject:self.arr[indexPath.row]];
[self.tab reloadData];

}

@end


                                    苹果自带地图1.创建导航 在导航上创建定位按钮

2.引入两个依赖库 一个是地图的 一个是定位的

此处导两个库

在VC.m里面:
引入两个框架 地图和定位的框架

#import “ViewController.h”
//引入头文件 ‘地图框架’
#import <MapKit/MapKit.h>
//引入头文件 ‘定位框架’
#import <CoreLocation/CoreLocation.h>
@interface ViewController ()<MKMapViewDelegate , CLLocationManagerDelegate>
//定义属性 ‘地图视图’
@property(nonatomic,strong)MKMapView *MapView;
//定义属性 ‘地理位置管理者’
@property(nonatomic,strong)CLLocationManager *locManager;
@end

@implementation ViewController

(void)viewDidLoad {
[super viewDidLoad];

self.title = @“地图”;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@“附近违章高发地” style:UIBarButtonItemStyleDone target:self action:@selector(click)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@“定位” style:UIBarButtonItemStyleDone target:self action:@selector(currentBtnDidPress:)];

//初始化MKMapView ‘地图视图’
self.MapView = [[MKMapView alloc]initWithFrame:self.view.frame];
//设置地图的样式 ‘MKMapTypeSatellite卫星地图’ ‘MKMapTypeStandard平面地图’
self.MapView.mapType = MKMapTypeStandard;
//签订协议
self.MapView.delegate = self;
//添加到视图
[self.view addSubview:self.MapView];

//实例化位置管理者对象
self.locManager = [[CLLocationManager alloc]init];
//签订协议
self.locManager.delegate = self;
//申请用户授权
[self.locManager requestWhenInUseAuthorization];

}
-(void)click{

// NextViewController *next = [[NextViewController alloc]init];
// [self.navigationController pushViewController:next animated:YES];

}
//获取当前按钮触发
-(void)currentBtnDidPress:(id)sender{

//开始获取位置信息,调用此方法后,协议中的方法才会执行
[self.locManager startUpdatingLocation];//通过位置管理者开始位置更新

}

//获取当前位置信息后触发的回调方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{

//获取当前位置 CLLocation位置 locations位置信息一个数组,获取最后一个最新的位置信息
CLLocation *cation = [locations lastObject];
//获取经纬度 coordinate坐标 ‘经纬度=当前位置的坐标’
CLLocationCoordinate2D locationCoor = cation.coordinate;
//输出一下位置信息 longitude经度 latitude纬度
NSLog(@“位置:经度:%g,纬度:%g”,locationCoor.longitude,locationCoor.latitude);

//让地图的显示区缩小 MKCoordinateRegion显示区 传入一个经纬度 和两个需要缩成的大小
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(locationCoor, 180, 180);
//添加到地图视图上 给地图缩小
[self.MapView setRegion:region animated:YES];

//反向地址解析,将经纬度转换为字符串
//初始化地址解析 ‘CLGeocoder地址解析’
CLGeocoder *geocoder = [[CLGeocoder alloc]init];
//解析 reverseGeocodeLocation传入一个位置
[geocoder reverseGeocodeLocation:cation completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {

//获取其中的一个地址信息
CLPlacemark *place = [placemarks lastObject];//做一个大头针
//初始化一个描点
MKPointAnnotation *point = [[MKPointAnnotation alloc]init];
//设置大头针的标题   显示当前的位置信息
point.title = [NSString stringWithFormat:@"我的位置:%@",place.name];
//设置大头针显示的经纬度  传入locationCoor当前的经纬度
point.coordinate = locationCoor;
//添加到地图上   必须是Annotation的类型
[self.MapView addAnnotation:point];

}];

}
//设置锚点视图的回调方法,当地图调用addAnnotation:方法时会触发 点击大头针是触发的方法
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation{
//静态字符串标识
static NSString *iden = @“pin”;
//初始化描点视图
MKPinAnnotationView *pin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:iden];

//设置掉落状态
pin.animatesDrop = YES;
//设置泡泡效果
pin.canShowCallout = YES;

return pin;

}

@end

解析 数据库 苹果自带地图相关推荐

  1. ios-跳转到苹果自带地图进行导航

    在某些应用中可能会出现,我们输入某个位置,然后点击导航,会跳到苹果自带的地图中进行导航,这应该怎么做? 其实很简单,首先我们需要根据输入的地名进行地理编码, 调用方法去得到地标对象,然后去获取CLPl ...

  2. ios开发中如何调用苹果自带地图导航

    前段时间一直在赶项目,在外包公司工作就是命苦,天天加班不说,工作都是和工期合同挂钩的,稍微逾期就有可能被扣奖金,不谈这些伤脑筋的事情了,让我们说说iOS开发中如何调用苹果手机自带的地图. 学习如逆水行 ...

  3. swift中检测跳转苹果自带地图、高德地图、百度地图、腾讯地图

    首先申明,此文章是转载 我是闰土你是猹 博主的文章,觉得有用,就拿过来,确实不好找相关案例,特此记录一下!大家可以移步文章原地址:https://blog.csdn.net/qq_30932479/a ...

  4. IOS 苹果自带地图、百度地图、高德地图打开方式

    //手机自带地图 //当前位置 MKMapItem *mylocation = [MKMapItemmapItemForCurrentLocation]; //前面填写纬度 CLLocationCoo ...

  5. 苹果自带地图定位 经纬度

    1.创建导航 在导航上创建定位按钮 2.引入两个依赖库 一个是地图的 一个是定位的 在VC.m里面: 引入两个框架 地图和定位的框架 #import "ViewController.h&qu ...

  6. 苹果自带地图进行定位

    最近项目中遇到了关于地图定位的需求,考虑到用三方库的话项目会变大,还是用了官方自带的地图. 这是结果图: 一.CoreLocation.frame是iPhone SDK中用来检测用户位置的框架. 1. ...

  7. iOS22 地图定位- 苹果自带地图

    引入两个框架,编码写成属性,初始化后,传入一个经纬度之后,展示地图: #import <CoreLocation/CoreLocation.h> #import <MapKit/Ma ...

  8. iOS 苹果自带地图需求开发——1

    在iOS开发的过程中,不可避免的要涉及到地图方面的需求,本人也刚刚实现了一些地图上面的需求所以整理了以下的一些实现方式. 1.实现景点(地点)的定位功能 比较简单 话不多说上代码 // 引入mapKi ...

  9. 苹果自带地图包括路线规划

    跟视图控制器: .h为: #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> #import <CoreBluetooth ...

最新文章

  1. C#中对文件File常用操作方法的工具类
  2. 【C++学习笔记三】C++多态、抽象(接口)
  3. apache目录 vscode_VsCode搭建Java开发环境(Spring Boot项目创建、运行、调试)
  4. 书籍推荐:零基础入门学习Python
  5. STM8单片机定时器1编码器功能使用详解
  6. Docker 容器资源管理,你真的学会了吗?
  7. Ext学习笔记02 - 构造方法,类继承,类实例方法重写
  8. android opencv 图像旋转90度,使用OpenCV转换图像( 旋转 90度)的简单方法?
  9. Ubuntu20.04之安装搜狗输入法
  10. Linux inode的正确理解
  11. PL2303 Windows8.1驱动的问题
  12. android通用对话框,android-所有活动中的“通用”对话框
  13. ue的 linux版本,UltraEdit Linux版RPM包 64位 V16.1.0.22
  14. OSPF基础配置命令
  15. Redis 官方可视化工具,功能真强大
  16. 轻量级cad绘图工具FoxCAD for mac
  17. NoClassDefFoundError:org.ksoap2.seri...
  18. c语言用函数求组合数编程,C语言函数 -C语言求组合数
  19. 洛谷 P3987 我永远喜欢珂朵莉~(Splay+BIT+无限卡常)
  20. 三年级计算机 键盘指法 教案,第13课 键盘指法练习

热门文章

  1. 利用Excel Power Query获取基金历史净值、估值和日增长率等信息
  2. Jmeter+Prometheus+Grafana性能监控平台:将JMeter压测数据输出到Prometheus
  3. 从荣耀V20看技术人怎么销售自己
  4. 红米K30S至尊纪念版和红米K30至尊纪念版哪个好
  5. 老司机带你从源码开始撸Spring生命周期!!!
  6. 苏宁易购不易购,遭遇临时涨价、一月未送货
  7. JavaWEB(AJAX实现分页)
  8. 用英语介绍一下计算机专业,“计算机专业英文自我介绍范文” 英语自我介绍...
  9. 简单了解计算机编码知识-(中文编码)
  10. ng-content、ng-template、ng-container使用及区别