誰かが私が取り組んできた問題を解決してくれることを願っています...
MapBox を使用して地図ベースのアプリを開発し、各地図注釈に NSMutableDictionary をアタッチして追加データを保存したいと考えています。私はそれを機能させましたが、XCode は私のデータ/オブジェクト型のいくつかについて警告を出し続けたので、それらを調べて片付けましたが、今は壊れています。アイデアは、ViewDidLoad で、プログラムが plist 辞書のセットを実行して各注釈を正しく設定するというものです。最初の anno マーカーが正しい設定でポップアップするため、それでも問題なく実行されます。ただし、毎回 plist に戻るのではなく、各注釈の userinfo プロパティにディクショナリをアタッチして、選択データの切り替えやその他の機能に使用できるようにしたいと考えています。これが私のコードです:
NSDictionary *ExploreSteps = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ExploreSteps" ofType:@"plist"]];
for (NSString *key in [ExploreSteps allKeys])
{
//Loop through keys for each anno
NSDictionary *thisStep = [ExploreSteps objectForKey:key];
NSNumber *annoIndex = [thisStep objectForKey:@"Index"];
NSNumber *isLive = [thisStep valueForKey:@"isLive"];
NSString *annoTitle = [thisStep objectForKey:@"Title"];
NSString *annoText = [thisStep objectForKey:@"Text"];
NSString *imagefile = [thisStep objectForKey:@"Imagefile"];
double longitude = [[thisStep objectForKey:@"Longitude"] doubleValue];
double latitude = [[thisStep objectForKey:@"Latitude"] doubleValue];
NSString *pagefile = [thisStep objectForKey:@"Pagefile"];
NSString *audiofile = [thisStep objectForKey:@"Audiofile"];
CLLocationCoordinate2D annoCoord = CLLocationCoordinate2DMake(latitude, longitude);
RMAnnotation *annotation = [[RMAnnotation alloc] initWithMapView:mapView coordinate:annoCoord andTitle:annoTitle];
annotation.annotationIcon = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:imagefile ofType:@"png"]];
annotation.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:annoIndex, @"index", isLive, @"isLive", annoTitle, @"annoTitle", annoText, @"annoText", imagefile, @"imagefile", pagefile, @"pagefile", audiofile, @"audiofile", nil];
NSLog(@"Title: %@",[annotation.userInfo objectForKey:@"annoTitle"]);
[mapView addAnnotation:annotation];
}
NSLog は annoTitle 文字列を吐き出す必要がありますが、代わりに毎回 null が返され、アプリの残りの動作からも、辞書に保存されている情報が単純に「通過」していないことがわかります。
何か案は?前もって感謝します!
ETA: 辞書を初期化するための修正されたコード (問題に違いがあるようには見えません!):
NSMutableDictionary *myUserInfo = [[NSMutableDictionary alloc] initWithObjectsAndKeys:annoIndex, @"index", isLive, @"isLive", annoTitle, @"annoTitle", annoText, @"annoText", imagefile, @"imagefile", pagefile, @"pagefile", audiofile, @"audiofile", nil];
annotation.userInfo = myUserInfo;
NSLog(@"Title: %@",[annotation.userInfo objectForKey:@"annoTitle"]);
NSLog(@"Length: %u",[[annotation.userInfo allKeys] count]);
(Title は "(null)" を返しますが、Length は "1" を返します。これが役に立ったら...)