当我尝试在模拟器(3.1.3,Xcode 3.1.4)上启动我的应用程序时,它显示objc_msgSend且应用程序未启动。仅当我分配NSMUtable数组时,才会发生这种情况
这是我的代码部分,
在viewDidLoad中,
-(void)viewDidLoad{
locationArray = [[NSMutableArray alloc] initWithObjects:@"new delhi", @"faridabad",@"meerut"];
str1=[locationArray objectAtIndex:0];
str2=[locationArray objectAtIndex:1];
[super viewDidLoad];
}
然后我想在以下方法中使用locationArray对象;
-(CLLocationCoordinate2D) addressLocation1{
double latitude = 0.0;
double longitude = 0.0;
NSString *str= [locationArray NSString *str= [locationArray objectAtIndex:0];
//NSString *str= @"new delhi"
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",
[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSArray *listItems = [locationString componentsSeparatedByString:@","];
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
}
else {
//Show error
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
return location;
}
仅当分配locationArray时出现问题,我怎么了,请帮忙
谢谢
最佳答案
locationArray = [[NSMutableArray alloc] initWithObjects:@"new delhi", @"faridabad",@"meerut"];
尝试locationArray = [[NSMutableArray alloc] initWithObjects:@"new delhi", @"faridabad",@"meerut", nil];
从The NSArray docs中,您可以看到initWithObjects:
需要以nil
终止。如果您不想这样做,并且知道有多少,则可以使用initWithObjects:count: