表格地图

定位到我的位置
需在info.plist中添加:

Privacy - Location Always and When In Use Usage Description
Privacy - Location Always Usage Description
Privacy - Location When In Use Usage Description
在这里插入图片描述

地图:
在.h中,
创建属性@property(nonatomic,strong)NSString *provie;

在.m代码:
#import “MapUIkit.h”
//导入系统类
#import <MapKit/MapKit.h>
//导入获取经纬度类
#import <CoreLocation/CoreLocation.h>
//设置协议

@interface MapUIkit ()<MKMapViewDelegate,CLLocationManagerDelegate>

//创建地图对象
@property(nonatomic,strong)MKMapView *MapView;
@property(nonatomic,strong)CLLocationManager *lomanger;

@end

@implementation MapUIkit
-(void)viewDidLoad {
[super viewDidLoad];

//设置导航标题
self.navigationItem.title =self.provie;
//设置右侧按钮
//self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"省会定位" style:UIBarButtonItemStyleDone target:self action:@selector(YOU:)];
//实例化
self.MapView = [[MKMapView alloc] initWithFrame:self.view.frame];
//设置代理
self.MapView.delegate = self;
//设置地图样式
self.MapView.mapType = MKMapTypeStandard;
//加载视图
[self.view addSubview:self.MapView];
//设置按钮
UIButton *butt = [UIButton buttonWithType:UIButtonTypeCustom];
//设置
butt.frame = CGRectMake(40, 600,50, 50);
//添加文字
[butt setTitle:@"当前位置" forState:UIControlStateNormal];
butt.titleLabel.font = [UIFont systemFontOfSize:10];
//添加点击事件
[butt addTarget:self action:@selector(dian:) forControlEvents:UIControlEventTouchUpInside];
butt.layer.masksToBounds = YES;
butt.layer.cornerRadius = 25;
butt.backgroundColor = [UIColor greenColor];
//添加视图
[self.view addSubview:butt];
//实例化经纬度类
self.lomanger = [[CLLocationManager alloc] init];
//申请用户授权用户进入后台不在授权
[self.lomanger requestWhenInUseAuthorization];

}
-(void)YOU:(id)seb{

CLGeocoder *g = [[CLGeocoder alloc] init];
//将地址字符串转换为位置的经纬度
[g geocodeAddressString:self.provie completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
    //获取位置随便展示在地图上
    CLPlacemark *place = [placemarks lastObject];
    //获取位置
    CLLocation *loc =place.location;
    CLLocationCoordinate2D coor = loc.coordinate;
    //定位
    MKPointAnnotation *anne = [[MKPointAnnotation alloc] init];
    //设置挫钉
    anne.coordinate = coor;
    //回到主线程
    dispatch_async(dispatch_get_main_queue(), ^{
        //设置让地图显示区域缩小
        MKCoordinateRegion rgin =MKCoordinateRegionMakeWithDistance(coor, 10, 10);
        //添加到视图
        [self.MapView setRegion:rgin];
        [self.MapView addAnnotation:anne];
    });
}];

}
//实现点击方法
-(void)dian:(id)sender{

//设置代理
self.lomanger.delegate = self;
//开始获取位置信息 调用此方法后协议中的方法才会执行
[self.lomanger startUpdatingLocation];

}
//实现代理方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{

//创建对象获取当前获取最后一个元素
CLLocation *curloc = [locations lastObject];
//创建结构体 获取经纬度
CLLocationCoordinate2D curCoor = curloc.coordinate;
self.lomanger.delegate = nil;
//输出经纬度
NSLog(@"经度%g,纬度%g",curCoor.longitude,curCoor.latitude);

//设置让地图显示区域缩小
MKCoordinateRegion rgin =MKCoordinateRegionMakeWithDistance(curCoor, 30, 30);
//设置动画并添加
[self.MapView setRegion:rgin animated:YES];
//将地址经纬度转换为字符串
CLGeocoder *Geder = [[CLGeocoder alloc] init];
//设置方法
[Geder reverseGeocodeLocation:curloc completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
    
    //创建异步队列回到主线程
    dispatch_async(dispatch_get_main_queue(), ^{
       
        //获取最后一个经纬度转换为字符串
        CLPlacemark *place = [placemarks firstObject];
        //设置大头针
        MKPointAnnotation *pino = [[MKPointAnnotation alloc] init];
        //将获取的地址名字给大头针
        pino.title = place.name;
        //设置大头针的位置
        pino.coordinate = curCoor;
        //添加到地图上
        [self.MapView addAnnotation:pino];
    });
}];

}
//实现大头针点击事件
-(nullable MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation{

//从MAPView找一块可用的内存
MKPinAnnotationView *kl =[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"1"];
//设置动画
kl.animatesDrop = YES;
//设置
kl.canShowCallout = YES;
//返回内容
return kl;

}
@end

表格第一个页面:
#import “ONEViewController.h”
#import “MapUIkit.h”

@interface ONEViewController ()<UITableViewDelegate,UITableViewDataSource>
{
UITableView * tbv;
UIScrollView *scro;
UIPageControl *pag;
NSTimer *timer;
int k;
}
@end
@implementation ONEViewController

-(void)viewDidLoad {
[super viewDidLoad];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"周边" style:UIBarButtonItemStylePlain target:self action:@selector(dian)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"北京" style:UIBarButtonItemStylePlain target:self action:nil];
self.navigationController.navigationBar.backgroundColor = [UIColor yellowColor];
self.view.backgroundColor = [UIColor whiteColor];
UISearchBar * sea = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
sea.placeholder =@"请输入搜索的商品";
self.navigationItem.titleView = sea;
tbv = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
tbv.dataSource = self;
tbv.delegate = self;

[self.view addSubview:tbv];

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

return 2;

}

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

if (section==0) {
    return 3;
}else{
    return 1;
}

}

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

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"2"];

if (!cell) {
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"2"];
}

if (indexPath.section==0) {
    if (indexPath.row ==0) {
        tbv.rowHeight = 200;
        // 初始化滚动式图
        scro = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
        // 设置滚动范围
        scro.contentSize = CGSizeMake(3 * self.view.frame.size.width, 0);
        // 禁用弹簧效果
        scro.bounces = NO;
        // 禁用水平滚动
        scro.showsHorizontalScrollIndicator = NO;
        // 设置整页滚动
        scro.pagingEnabled = YES;
        // 设置代理
        scro.delegate = self;
        // 设置滚动图片
        for(int i = 0 ; i < 3 ; i++){
            // 设置图片数组
            NSArray *arr = @[@"1",@"2",@"3"];
            UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.frame.size.width, 0, self.view.frame.size.width, 200)];
            // 加载图片
            imgV.image = [UIImage imageNamed:arr[i]];
            // 添加到滚动视图中
            [scro addSubview:imgV];
            
        }
        // 添加到cell中
        [cell addSubview:scro];
        // 设置豆豆
        pag = [[UIPageControl alloc]initWithFrame:CGRectMake(90, 95, 150, 25)];
        // 设置豆豆的数量
        pag.numberOfPages = 3;
        // 设置豆豆的颜色
        pag.currentPageIndicatorTintColor = [UIColor orangeColor];
        pag.pageIndicatorTintColor = [UIColor whiteColor];
        // 添加到单元格中
        [cell addSubview:pag];
        // 创建定时器
        timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(aaa) userInfo:nil repeats:YES];

    }else if(indexPath.row ==1){
        tbv.rowHeight = 100;
        UIImageView * ima = [[UIImageView alloc]initWithFrame:CGRectMake(40, 10, 50, 50)];
        ima.image = [UIImage imageNamed:@"11"];
        ima.layer.masksToBounds = YES;
        ima.layer.cornerRadius = 25;
        [cell addSubview: ima];
        
        UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(40, 70, 60, 20)];
        lab.text = @"全部任务";
        lab.font = [UIFont systemFontOfSize:10];
        [cell addSubview:lab];
        
        UIImageView * ima1 = [[UIImageView alloc]initWithFrame:CGRectMake(140, 10, 50, 50)];
        ima1.image = [UIImage imageNamed:@"22"];
        ima1.layer.masksToBounds = YES;
        ima1.layer.cornerRadius = 25;
        [cell addSubview: ima1];
        
        UILabel * lab1 = [[UILabel alloc]initWithFrame:CGRectMake(140, 70, 60, 20)];
        lab1.text = @"全部任务";
        lab1.font = [UIFont systemFontOfSize:10];
        [cell addSubview:lab1];
        
        UIImageView * ima2 = [[UIImageView alloc]initWithFrame:CGRectMake(220, 10, 50, 50)];
        ima2.image = [UIImage imageNamed:@"33"];
        ima2.layer.masksToBounds = YES;
        ima2.layer.cornerRadius = 25;
        [cell addSubview: ima2];
        
        UILabel * lab2 = [[UILabel alloc]initWithFrame:CGRectMake(220, 70, 60, 20)];
        lab2.text = @"全部任务";
        lab2.font = [UIFont systemFontOfSize:10];
        [cell addSubview:lab2];
        
        UIImageView * ima3 = [[UIImageView alloc]initWithFrame:CGRectMake(300, 10, 50, 50)];
        ima3.image = [UIImage imageNamed:@"44"];
        ima3.layer.masksToBounds = YES;
        ima3.layer.cornerRadius = 25;
        [cell addSubview: ima3];
        
        UILabel * lab3 = [[UILabel alloc]initWithFrame:CGRectMake(300, 70, 60, 20)];
        lab3.text = @"全部任务";
        lab3.font = [UIFont systemFontOfSize:10];
        [cell addSubview:lab3];
    }else{
        tbv.rowHeight = 100;
        UIImageView * ima = [[UIImageView alloc]initWithFrame:CGRectMake(40, 10, 50, 50)];
        ima.image = [UIImage imageNamed:@"55"];
        ima.layer.masksToBounds = YES;
        ima.layer.cornerRadius = 25;
        [cell addSubview: ima];
        
        UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(40, 70, 60, 20)];
        lab.text = @"全部任务";
        lab.font = [UIFont systemFontOfSize:10];
        [cell addSubview:lab];
        
        UIImageView * ima1 = [[UIImageView alloc]initWithFrame:CGRectMake(140, 10, 50, 50)];
        ima1.image = [UIImage imageNamed:@"66"];
        ima1.layer.masksToBounds = YES;
        ima1.layer.cornerRadius = 25;
        [cell addSubview: ima1];
        
        UILabel * lab1 = [[UILabel alloc]initWithFrame:CGRectMake(140, 70, 60, 20)];
        lab1.text = @"全部任务";
        lab1.font = [UIFont systemFontOfSize:10];
        [cell addSubview:lab1];
        
        UIImageView * ima2 = [[UIImageView alloc]initWithFrame:CGRectMake(220, 10, 50, 50)];
        ima2.image = [UIImage imageNamed:@"77"];
        ima2.layer.masksToBounds = YES;
        ima2.layer.cornerRadius = 25;
        [cell addSubview: ima2];
        
        UILabel * lab2 = [[UILabel alloc]initWithFrame:CGRectMake(220, 70, 60, 20)];
        lab2.text = @"全部任务";
        lab2.font = [UIFont systemFontOfSize:10];
        [cell addSubview:lab2];
        
        UIImageView * ima3 = [[UIImageView alloc]initWithFrame:CGRectMake(300, 10, 50, 50)];
        ima3.image = [UIImage imageNamed:@"88"];
        ima3.layer.masksToBounds = YES;
        ima3.layer.cornerRadius = 25;
        [cell addSubview: ima3];
        
        UILabel * lab3 = [[UILabel alloc]initWithFrame:CGRectMake(300, 70, 60, 20)];
        lab3.text = @"全部任务";
        lab3.font = [UIFont systemFontOfSize:10];
        [cell addSubview:lab3];
    }
}else{
    tbv.rowHeight = 300;
    UIImageView * iam = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 300)];
    iam.image = [UIImage imageNamed:@"ff"];
    [cell addSubview:iam];
    
}

return cell;

}
-(void)dian{

[self.navigationController pushViewController:[MapUIkit new] animated:YES];

}
// 滚动视图
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

// NSLog(@"%lf",scro.contentOffset.x);
pag.currentPage = scro.contentOffset.x/self.view.frame.size.width;

}
// 定时器
-(void)aaa{

[scro setContentOffset:CGPointMake(k * self.view.frame.size.width, 0)];
k ++;
if(k > 2){
    k = 0;
}

}
@end

表格第二页页面:

-(void)viewDidLoad {
[super viewDidLoad];

tbv = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
tbv.dataSource = self;
tbv.delegate = self;
arr = @[@"我的包裹",@"我的包裹",@"我的包裹",@"我的包裹",@"我的包裹",@"我的包裹",@"我的包裹",@"我的包裹"];
imarr = @[@"111",@"222",@"333",@"444",@"555",@"666",@"777",@"888"];
UIView * uiv = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
uiv.backgroundColor = [UIColor orangeColor];
UIImageView * ima = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 100, 100)];
ima.image = [UIImage imageNamed:@"gg"];
ima.layer.masksToBounds= YES;
ima.layer.cornerRadius = 50;
UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(180, 45, 100, 40)];
lab.text = @"12312312";
UIImageView * imag = [[UIImageView alloc]initWithFrame:CGRectMake(0, 150, self.view.frame.size.width, 50)];
imag.image = [UIImage imageNamed:@"hh"];
[uiv addSubview:imag];
[uiv addSubview:ima];
[uiv addSubview:lab];
tbv.tableHeaderView = uiv;
tbv.rowHeight = 40;
[self.view addSubview:tbv];

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

return arr.count;

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

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"2"];
if (!cell) {

    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"2"];
}

cell.imageView.image = [UIImage imageNamed:imarr[indexPath.row]];
cell.textLabel.text = arr[indexPath.row];
UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(350, 0, 40, 40)];
lab.text = @">";
lab.textColor = [UIColor lightGrayColor];
[cell addSubview:lab];
return cell;

}
@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值