Ios 如何根据开关位置限制阵列负载

Ios 如何根据开关位置限制阵列负载,ios,xcode,annotations,switch-statement,nsuserdefaults,Ios,Xcode,Annotations,Switch Statement,Nsuserdefaults,我从plist和loop类别加载注释 NSMutableArray *annotations = [[NSMutableArray alloc]init]; NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]; NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; for(path in dict

我从plist和loop类别加载注释

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];

}

}   

我需要通过此开关限制特定类别注释的显示。如果我循环类别,该如何操作?

在第一个循环中,执行以下操作:

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?
    }

如果您需要测试特定条件,请尽可能确定是否满足该条件。

我有7个类别和7个开关,我需要通过这个开关来限制我的类别。我根据你讨论的类别和一个名为category的字符串更改了我的答案。它说“ann”是未使用的变量。我不是在为你编写代码,伙计。你必须使这些东西适应你的项目。我不知道您的条件是什么,因此ann对象未使用,因为您必须决定何时执行第二个循环对不起,更改了上面的注释,使其看起来不像dbag
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?
    }