gpt4 book ai didi

ios - 应用程序试图在目标 mapkit 公开按钮上推送一个 nil View Controller

转载 作者:行者123 更新时间:2023-11-29 03:04:43 24 4
gpt4 key购买 nike

我正在尝试在以 json 解析的位置处的注释标注中添加一个披露按钮。我已经实现了披露按钮,一切似乎都工作正常,直到按下披露按钮并且我收到此错误应用程序试图在目标上推送一个零 View Controller

这是我的第一个 viewController 的代码

#import "ViewController.h"
#import "DetailViewController.h"
#import "Annotation.h"

#import "City.h"

@interface ViewController ()
@property (nonatomic, strong) IBOutlet DetailViewController *detailViewController;


@end
#define getDatalURL @"http://www.club-hop.com/apptest.php"

@implementation ViewController

@synthesize mapView,jsonArray,citiesArray;


- (void)viewDidLoad
{
[super viewDidLoad];
[self retrieveData];

/* Zoom the map to current location.
[self.mapView setShowsUserLocation:YES];
[self.mapView setUserInteractionEnabled:YES];
[self.mapView setUserTrackingMode:MKUserTrackingModeFollow];*/
City * cityObject;

// load external page into UIWebView
NSMutableArray * locations= [[NSMutableArray alloc]init];
CLLocationCoordinate2D location;
Annotation * myAnn;

for(int u=0; u<citiesArray.count;u++){
cityObject=[citiesArray objectAtIndex:u];

myAnn=[[Annotation alloc]init];
NSNumber *aLat= cityObject.Latitude;
NSNumber *aLon= cityObject.Longitude;

double lat = [aLat doubleValue];
double lon = [aLon doubleValue];

location.latitude= lat;
location.longitude=lon;
myAnn.coordinate = location;
myAnn.title=cityObject.clubName;
myAnn.subtitle=cityObject.cityName;
[locations addObject:myAnn];}

[self.mapView addAnnotations:locations];


}

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



//class methods
-(void) retrieveData{
NSURL * url= [NSURL URLWithString:getDatalURL];
NSData * data= [NSData dataWithContentsOfURL:url];
jsonArray= [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

//setup cities array
citiesArray=[[NSMutableArray alloc]init];

for(int i=0; i<jsonArray.count;i++){
NSString * cID= [[jsonArray objectAtIndex:i] objectForKey:@"id"];
NSString * cName= [[jsonArray objectAtIndex:i] objectForKey:@"cityName"];
NSString * cCountry= [[jsonArray objectAtIndex:i] objectForKey:@"cityCountry"];
NSString * cLine= [[jsonArray objectAtIndex:i] objectForKey:@"clubLine"];
NSString * clName= [[jsonArray objectAtIndex:i] objectForKey:@"clubName"];
NSNumber * cLatitude= [[jsonArray objectAtIndex:i] objectForKey:@"Latitude"];
NSNumber * cLongitude= [[jsonArray objectAtIndex:i] objectForKey:@"Longitude"];

[citiesArray addObject:[[City alloc]initWithCityName:cName andCityCountry:cCountry andClubName:clName andClubLine:cLine andLatitude:cLatitude andLongitude:cLongitude andCityId:cID]];

}

}

#pragma mark - MKMapViewDelegate

// user tapped the disclosure button in the callout
//
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
id <MKAnnotation> annotation = [view annotation];
if ([annotation isKindOfClass:[Annotation class]])
{
NSLog(@"clicked annotation");
}

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

}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{

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

if (!pinView)
{
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"] ;
pinView.pinColor=MKPinAnnotationColorGreen;
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
UIButton * rightButton= [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView=rightButton;
}
else{
pinView.annotation=annotation;
}
return pinView;

}


@end

如果能解释我收到此错误的原因,我们将不胜感激。

最佳答案

您还没有分配或初始化 self.detailViewController。您创建了一个名为 detailViewController 的属性,但从未对它执行任何操作。

试试这个:

- (void)viewDidLoad
{
self.detailViewController = [[DetailViewController alloc] init];
}

关于ios - 应用程序试图在目标 <UINavigationController> mapkit 公开按钮上推送一个 nil View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22913163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com