当我尝试在模拟器(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 时才会出现问题,请帮忙 感谢
答案 0 :(得分:7)
locationArray = [[NSMutableArray alloc] initWithObjects:@"new delhi", @"faridabad",@"meerut"];
尝试
locationArray = [[NSMutableArray alloc] initWithObjects:@"new delhi", @"faridabad",@"meerut", nil];
从The NSArray docs开始,您会看到initWithObjects:
需要nil
终止。如果您不想这样做,并且您知道自己拥有多少,则可以使用initWithObjects:count: