我正在研究 mapView 项目。我的项目将只在地图上使用 5 个注释。添加新注释后,将删除第一个注释。我将所有注释纬度和经度保存到 NSMutableStringArray 中。有没有什么捷径可以实现这种循环方式。先进后出。
例如我的 nsmutable 字符串:
[12.99, 35.97: 35.85,94.53: 45.44,98.91]
我怎样才能从字符串中删除第一个对象(每个字符串由列运算符:) 来获取以下内容:
[35.85,94.53: 45.44,98.91]
我正在研究 mapView 项目。我的项目将只在地图上使用 5 个注释。添加新注释后,将删除第一个注释。我将所有注释纬度和经度保存到 NSMutableStringArray 中。有没有什么捷径可以实现这种循环方式。先进后出。
例如我的 nsmutable 字符串:
[12.99, 35.97: 35.85,94.53: 45.44,98.91]
我怎样才能从字符串中删除第一个对象(每个字符串由列运算符:) 来获取以下内容:
[35.85,94.53: 45.44,98.91]
使用NSMutableArray本身有什么问题。或者我不明白你的问题?
NSMutableArray *queue = [[NSMutableArray alloc] init];
if([queue count] >= 5)
[queue addObject: myObject]; // adds at end
else
object = [queue objectAtIndex:5]; // take out the first added object
[queue removeObjectAtIndex:0];
我已经成功了,我的解决方案如下:
NSMutableString *absolute=[NSMutableString stringWithString:pinPoints];
NSLog(@"before absolute: %@",absolute);
NSArray *placemarks=[absolute componentsSeparatedByString:@":"];
if([placemarks count]>5)
{
//NSLog(@"%@",[placemarks objectAtIndex:0]);
NSMutableString *string1 = [NSMutableString stringWithString: [placemarks objectAtIndex:0]];
[absolute replaceOccurrencesOfString:string1 withString:@"" options:0 range:NSMakeRange(0,[pinPoints length])];
pinPoints=absolute;
}
NSLog(@"after absolute: %@",absolute);