在我的viewWillAppear中我有一个视图
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
[point setCoordinate:(myLocation)];
[point setTitle:@"Here it is!"];
[mapView addAnnotation:point];
[mapView setRegion:adjustedRegion animated:YES];
Run Code Online (Sandbox Code Playgroud)
这就像我想要的那样为地图增加了一点.但是我必须点击它才能看到标注.
如何默认显示标注?
我尝试在以下之后添加:
[self.mapView selectAnnotation:annotation animated:YES];
但它似乎没有用......我必须使用真正的注释而不是MKPointAnnotation来做到这一点吗?
我正在尝试创建一个临时的托管对象上下文,在用户输入信息的几个屏幕之后,我将该上下文与主上下文合并(以确保没有插入"不完整"的对象).这是我创建临时上下文以及如何在其中插入对象的方法:
if (!self.someManagedObject) {
NSManagedObjectModel *model = [NSManagedObjectModel mergedModelFromBundles:@[[NSBundle mainBundle]]];
NSPersistentStoreCoordinator *storeCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
[storeCoordinator addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:nil];
NSManagedObjectContext *managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator:storeCoordinator];
self.someManagedObject = [NSEntityDescription insertNewObjectForEntityForName:@"SomeObject" inManagedObjectContext:managedObjectContext];
NSLog(@"%@", self.someManagedObject.managedObjectContext);
}
Run Code Online (Sandbox Code Playgroud)
这是其中的一部分viewDidLoad.在控制台中,它显示托管对象上下文具有值.
然而,就在这个if语句之后(即使在内viewDidLoad,self.someManagedObject.managedObjectContext也是nil.我可以看到为什么局部变量不再可用(它只是超出范围),但是仍然应该设置托管对象的属性,对吧?
我知道我可以创建一个属性来存储托管对象上下文,但我宁愿让它以这种方式工作.
我正在我的应用程序中安排和取消区域监控,如下所示.
- (void) setLocationReminderForLatitude:(double) latitude longitude:(double) longitude radiusInMetres:(double) radius withIdentifier:(NSString *) identifier
{
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:CLLocationCoordinate2DMake(latitude, longitude) radius:radius identifier:identifier];
[coreLocation startMonitoringForRegion:region desiredAccuracy:50]; //50 metres
}
- (void) cancelLocationNotification:(NSString *)identifier
{
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:CLLocationCoordinate2DMake(0.0, 0.0) radius:100.0 identifier:identifer];
[coreLocation stopMonitoringForRegion:region];
}
Run Code Online (Sandbox Code Playgroud)
在取消区域监控时,我可能不一定具有我最初用于开始监控该区域的中心和半径信息,但标识符是正确的.这会有用吗?
文档中没有提到任何相关内容.
我在网上看到了很多关于这个的问题,似乎找不到可靠的答案.如果我有一个在蜂窝数据上运行的iPhone和另一个在wifi上的iOS设备(在两个不同的位置),他们是否有可能直接向对方发送数据而不先将其发送到Web服务器,然后检索它?是否是从服务器/ Apple的iCloud发送和接收的唯一选项?如果我知道设备的IP地址怎么办?请注意,iPhone已禁用WiFi.
我不打算把它放在应用程序商店中,它是供个人使用的.我知道NSNotificationCenter不是一个选择.