Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Can';在初始用户位置触发后,无法获取要触发的通知的视图_Ios_Objective C_Ios6_Ios6 Maps - Fatal编程技术网

Ios Can';在初始用户位置触发后,无法获取要触发的通知的视图

Ios Can';在初始用户位置触发后,无法获取要触发的通知的视图,ios,objective-c,ios6,ios6-maps,Ios,Objective C,Ios6,Ios6 Maps,我有以下代码: // MapViewController.h #import <Foundation/Foundation.h> #import "MyCLController.h" #import <MapKit/MapKit.h> @class ShowsContainerController; @interface MapViewController : UIViewController <MyCLControllerDelegate,MKMapViewD

我有以下代码:

// MapViewController.h
#import <Foundation/Foundation.h>
#import "MyCLController.h"
#import <MapKit/MapKit.h>

@class ShowsContainerController;

@interface MapViewController : UIViewController <MyCLControllerDelegate,MKMapViewDelegate> {
    MyCLController *locationController;
    MKMapView *mapView;
}

- (void)locationUpdate:(CLLocation *)location;
- (void)locationError:(NSError *)error;

@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@property (assign) BOOL updateMap;
@property (strong) ShowsContainerController *parent;

@end

// MapViewController.m
#import "MapViewController.h"
#import "ShowsContainerController.h"

#define METERS_PER_MILE 1609.344

@implementation MapViewController

@synthesize parent, mapView;

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.updateMap = YES;
    locationController = [[MyCLController alloc] init];
    locationController.delegate = self;
    [locationController.locationManager startUpdatingLocation];
    mapView.delegate = self;
}

- (void)locationUpdate:(CLLocation *)location {

    if( self.updateMap ){
        MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);

        [mapView setRegion:viewRegion animated:YES];

        self.parent = (ShowsContainerController *)self.parentViewController;

        [self.parent setLocation:location];

        self.updateMap = NO;
    }
}

- (void)locationError:(NSError *)error {
    NSLog([error localizedDescription]);
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    self.parent.mapReady = YES;

    if( self.parent.locationSet ){
        [self.parent callApi];
    }
}

#pragma mark MKMapViewDelegate

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    NSLog(@"delegating user location");
    // if it's the user location, just return nil.
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    NSLog(@"delegating pins");
    static NSString* ShowAnnotationIdentifier = @"showAnnotationIdentifier";

    MKPinAnnotationView* pinView = (MKPinAnnotationView *)
    [mapView dequeueReusableAnnotationViewWithIdentifier:ShowAnnotationIdentifier];

    if (!pinView)
    {
        // if an existing pin view was not available, create one
        MKPinAnnotationView* customPinView = [[MKPinAnnotationView alloc]
                                              initWithAnnotation:annotation reuseIdentifier:ShowAnnotationIdentifier];
        customPinView.enabled = YES;
        customPinView.pinColor = MKPinAnnotationColorRed;
        customPinView.animatesDrop = YES;
        customPinView.canShowCallout = YES;

        return customPinView;
    }
    else
    {
        pinView.annotation = annotation;
    }
    return pinView;
}

#pragma mark -

@end
日志显示“委派用户位置”,但从不显示“委派PIN”。它甚至不会为用户的位置触发超过一个初始时间的注释视图


委派似乎正在工作,否则我将无法捕获此选择器,但为什么它仅针对用户位置而不针对后续添加的注释触发?

最明显的原因是,除了MKUserLocation one之外,您没有其他注释。尝试使用断点记录placeAnnotations:中的内容,并查看它是否曾经进入循环。它们也出现在地图上,但没有在viewForAnnotation中设置任何属性。它们没有动画,也没有标注框,我无法设置它们的pin颜色。在您的viewForAnnotation:方法中没有“委派用户位置”。是否确定已正确设置地图视图的委托?抱歉;粘贴代码后,我更新了代码。现在在示例中更新了它…我非常肯定您的代码应该可以工作。原因一定很小,很模糊,与您发布的两段代码无关。我宁愿在mapController本身中搜索问题
- (void)placeAnnotations:(NSArray *)shows
{

    NSEnumerator *e = [shows objectEnumerator];
    id show;
    NSMutableArray *annotations = [[NSMutableArray alloc] init];

    while (show = [e nextObject]) {
        double lat = [[[[[show objectForKey:@"venue"] objectForKey:@"location"] objectForKey:@"geo:point"] objectForKey:@"geo:lat"] doubleValue];
        double lng = [[[[[show objectForKey:@"venue"] objectForKey:@"location"] objectForKey:@"geo:point"] objectForKey:@"geo:long"] doubleValue];

        ShowAnnotation *annotation = [[ShowAnnotation alloc]
                                      initWithCoordinate:CLLocationCoordinate2DMake(lat, lng)
                                      withMap:self.mapController.mapView
                                      withTitle:[show objectForKey:@"title"]
                                      withSubtitle:[[show objectForKey:@"venue"] objectForKey:@"name" ]];
        [annotations addObject:annotation];
    }

    NSLog(@"adding annotations");
    [self.mapController.mapView addAnnotations:annotations];

}