我正在制作的应用程序Polyline根据用户坐标绘制CLLocationManager(这些都保存在一起NSMutableArray)
当应用关闭时,当前折线消失.如何在应用程序启动时存储要在CoreData中检索的点数组?用户在启动应用程序后所采取的所有过去"路线"应该被恢复并覆盖在地图上(这可能相当多,因此CoreData似乎是我收集的最佳选择).
这是我用来从加载的坐标创建MKPolyline的代码
-(IBAction)didClickLoadCoordinates:(id)sender {
// get a reference to the appDelegate so you can access the global managedObjectContext
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Route"];
NSError *error;
id results = [appDelegate.managedObjectContext executeFetchRequest:request error:&error];
if ([results count]) {
polyLine = (Route *)(results[0]);
NSArray *coordinates = polyLine.coordinates;
int ct = 0;
for (CLLocation *loc in coordinates) {
NSLog(@"location %d: %@", ct++, loc);
}
// this copies the array to your mutableArray …Run Code Online (Sandbox Code Playgroud) 我有一个简单的IBAction执行一个方法(我们只是说显示子视图).当我再次按下此按钮时,我想执行另一种方法(隐藏子视图).
我已经完成了show/hide的编码.我尝试使用布尔但不确定语法.我也试过像这样使用if/else语句:
var doubleTap = false
if (doubleTap) {
//hide view
} else {
//show view
}
Run Code Online (Sandbox Code Playgroud)
如果有人能够对此有所了解那就太棒了!