2012-06-01 86 views
0

我打開我的註解從plist中和循環類取決於開關位置

NSMutableArray *annotations = [[NSMutableArray alloc]init]; 

NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]; 
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; 

for(path in dict){ 

NSString *theCategory; 

theCategory = [NSString stringWithFormat:@"%@", path]; 
NSLog(@"%@", path); 

NSArray *ann = [dict objectForKey:theCategory]; 


for(int i = 0; i < [ann count]; i++) { 


    NSString *coordinates = [[ann objectAtIndex:i] objectForKey:@"Coordinates"]; 

    double realLatitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:1] doubleValue]; 
    double realLongitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:0] doubleValue]; 

    MyAnnotation *myAnnotation = [[MyAnnotation alloc] init]; 
    CLLocationCoordinate2D theCoordinate; 
    theCoordinate.latitude = realLatitude; 
    theCoordinate.longitude = realLongitude; 

    myAnnotation.coordinate=CLLocationCoordinate2DMake(realLatitude,realLongitude);   
    myAnnotation.title = [[ann objectAtIndex:i] objectForKey:@"Name"]; 
    myAnnotation.subtitle = [[ann objectAtIndex:i] objectForKey:@"Address"]; 
    myAnnotation.icon = [[ann objectAtIndex:0] objectForKey:@"Icon"]; 


    [mapView addAnnotation:myAnnotation]; 
    [annotations addObject:myAnnotation]; 

} 

} 

然後,我有一個開關在我的設置

- (IBAction)saveSwitch:(id)sender 
{ 
    NSUserDefaults *defs1 = [NSUserDefaults standardUserDefaults]; 
    [defs1 setBool: blackSwitch.on forKey: @"blackKey"]; 
    [[NSUserDefaults standardUserDefaults] synchronize]; 
} 

我需要限制顯示如何限制陣列的負載這個開關的特定類別的註釋。如何循環分類,如何完成?

回答

0

內,您的第一個循環,這樣做:

for(NSString *category in dict){ 
    if ([category isEqualToString:@"Whatever"]) { 
     //continue? 
     NSArray *ann = [dict objectForKey:category]; 
     BOOL blackKeyStatus = [[NSUserDefaults standardUserDefaults]boolForKey:@"blackKey"]; 

     if (blackKeyStatus) { 
      //switch ON 
      //act appropriatelyForOnValue 
      //begin Loop 2 here? 
     } else { 
      //switch OFF 
      //act appropriately 
     } 

    } else { 
     //do something else? 
    } 

如果你需要測試特定條件,採取一切必要措施,以確定是否滿足該條件。

+0

我有7個大類和7個開關,我需要限制我的類別由這個開關 –

+0

我改變了基於你討論類別和有我的回答一個字符串名爲「類別」 – Justin

+0

它說,「安」是未使用的變量 –