糯米团—重制“iPhone团购信息客户端”(四)

奥对,忘了说了,Xcode7已经默认https连接了,自动锁定了http连接
Solution:
1. 在Info.plist中添加 NSAppTransportSecurity 类型 Dictionary.
2. 在 NSAppTransportSecurity 下添加 NSAllowsArbitraryLoads 类型Boolean,value为YES


接下来写显示商品详情的类
GoodsDetail
storyboard上面怎么连接我就不说了,直接上代码。

WebViewController.h

#import <UIKit/UIKit.h>

@interface WebViewController : UIViewController

@property (strong, nonatomic) NSString *stringURL;
@property (strong, nonatomic) NSString *shopName;

@property (weak, nonatomic) IBOutlet UIWebView *webView;
- (IBAction)back:(UIBarButtonItem *)sender;

@end

WebViewController.m

#import "WebViewController.h"

@interface WebViewController ()

@end

@implementation WebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = [NSString stringWithFormat:@"%@", _shopName];
    NSURL *url = [NSURL URLWithString:_stringURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [_webView loadRequest:request];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)back:(UIBarButtonItem *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end

再来地图

ShowInMap

MapViewController.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "MyAnnotation.h"

@interface MapViewController : UIViewController <MKMapViewDelegate>

@property (strong, nonatomic) NSString *longtitudeStr;
@property (strong, nonatomic) NSString *latitudeStr;
@property (strong, nonatomic) NSString *shopName;
@property (strong, nonatomic) NSString *shopAddress;

@property (strong, nonatomic) CLLocationManager *locationManager;

@property (weak, nonatomic) IBOutlet MKMapView *map;

- (IBAction)back:(UIBarButtonItem *)sender;

@end

MapViewController.m


#import "MapViewController.h"

@interface MapViewController () {
    CLLocationDegrees longitude;
    CLLocationDegrees latitude;
}

@property (strong, nonatomic) CLLocation *targetLocation;
@property (strong, nonatomic) MyAnnotation *annotation;

- (void)gecodeToDisplayTargetLocation;

@end

@implementation MapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = _shopAddress;
    //定位请求
    _locationManager = [CLLocationManager new];
    [_locationManager requestWhenInUseAuthorization];
    //经纬转换
    longitude = (CLLocationDegrees)[_longtitudeStr floatValue];
    latitude = (CLLocationDegrees)[_latitudeStr floatValue];
    _targetLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
    _map.delegate = self;

    [self gecodeToDisplayTargetLocation];
}

- (void)gecodeToDisplayTargetLocation {
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:_targetLocation completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
        //传过来1个数据,所以就一个
        CLPlacemark *placemark = placemarks[0];
        //显示地图缩放比例
        MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(placemark.location.coordinate, 500, 500);
        [_map setRegion:viewRegion animated:YES];
        //设置标注
        _annotation = [MyAnnotation new];
        _annotation.shopName = _shopName;
        _annotation.address = _shopAddress;
        _annotation.coordinate = placemark.location.coordinate;
        [_map addAnnotation:_annotation];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - MKMapDelegate implements
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    //使用可重用对象节省内存
    MKPinAnnotationView *annotaionView = (MKPinAnnotationView *)[_map dequeueReusableAnnotationViewWithIdentifier:@"PIN_ANNOTATION"];
    if (!annotaionView) {
        annotaionView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"PIN_ANNOTATION"];
    }
    //设置大头针颜色
    annotaionView.pinColor = MKPinAnnotationColorPurple;
    //大头针动态插入
    annotaionView.animatesDrop = YES;
    //显示附加信息在大头针处
    annotaionView.canShowCallout = YES;

    return annotaionView;
}

- (IBAction)back:(UIBarButtonItem *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end

至于SecondViewController我没有写代码,这里随便怎么处置了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值