0

我目前使用一个系统,如果用户升级了应用程序,所有结果都在颜色图表中查看。

在 ViewController.m 的顶部

int kMaxRecords = 300;

就在数组之前;

allText = [[NSMutableArray alloc] init];

然后是 300 种颜色,例如;

[allText addObject:@"Indigo"]; 

等等 ...

这由 IBAction 控制;

- (IBAction)setRandomText {
    selectedRecNumber = (arc4random() % kMaxRecords);
    NSString *text = [allText objectAtIndex:selectedRecNumber];
    [randomText setText:text];

if ([MKStoreManager featureAPurchased]) {

        kMaxRecords = [allText count];

    }else{

        // this is where I would like to control a set limit of colors, let's say, 50, or 100

        }

    }

    count++;

}

那么在 }else{ 之后,我将如何设置,例如,只显示 300 种颜色中的前 100 种颜色?我尝试使用;

kMaxRecords = 100;

然而它没有工作......

编辑 -

为了进一步复杂化,让我们引入更多可能性;

 if ([MKStoreManager featureAPurchased] || [MKStoreManager featureDPurchased] ||[MKStoreManager featureEPurchased] ) {

        kMaxRecords = [allText count];

    }else{

            if (![MKStoreManager featureAPurchased] || ![MKStoreManager featureCPurchased] || ![MKStoreManager featureDPurchased] || ![MKStoreManager featureEPurchased] ) {

                kMaxRecords = 35; 
                allText = [[allText subarrayWithRange:NSMakeRange(0, 34)] mutableCopy];

        }else{

            if ([MKStoreManager featureCPurchased] ) {

                kMaxRecords = 135; 
                allText = [[allText subarrayWithRange:NSMakeRange(0, 134)] mutableCopy];

                }
            }

        }

}

编辑 2 - 这是 viewDidLoad;

- (void)viewDidLoad {

   allText = [[NSMutableArray alloc] init];

    [allText addObject:@"Green"];
    [allText addObject:@"Orange"];
    and more and more...



    if ([MKStoreManager featureAPurchased] || [MKStoreManager featureDPurchased] ||[MKStoreManager featureEPurchased] ) {

        kMaxRecords = [allText count];

    }else{

            if (![MKStoreManager featureAPurchased] || ![MKStoreManager featureCPurchased] || ![MKStoreManager featureDPurchased] || ![MKStoreManager featureEPurchased] ) {

                kMaxRecords = 35; 
                allText = [[allText subarrayWithRange:NSMakeRange(0, 34)] mutableCopy];

        }else{

            if ([MKStoreManager featureCPurchased] ) {

                kMaxRecords = 135; 
                allText = [[allText subarrayWithRange:NSMakeRange(0, 134)] mutableCopy];

                }
            }

        }

}

- (IBAction)setRandomText {

    selectedRecNumber = (arc4random() % kMaxRecords);
    NSString *text = [allText objectAtIndex:selectedRecNumber];
    [randomText setText:text];
    count++;

}
4

1 回答 1

0

您可以使用 subarrayWithRange: 重新定义 allText 以包含尽可能多的原始项目:

- (void)viewDidLoad {
     [super viewDidLoad];
     allText = [[NSMutableArray alloc] init];
     allText addObject:@"Indigo"];
     //... etc. until array is filled with 300 colors
     [self makeUserArray];
}

-(void)makeUserArray {
    if ([MKStoreManager featureAPurchased]) {
        kMaxRecords = [allText count];
    }else{
        kMaxRecords = 100; // or whatever number you want here
        usableText = [[allText subarrayWithRange:NSMakeRange(0, 100)] mutableCopy];
    }
}

- (IBAction)setRandomText {
    selectedRecNumber = (arc4random() % kMaxRecords);
    NSString *text = [usableText objectAtIndex:selectedRecNumber];
    [randomText setText:text];

    count++;
}
于 2013-07-15T20:20:39.187 回答