Question

I am having an issue selecting appropriate consumables that I have set up in iTunes Connect to appear in my table in a nib file. (Using Ray Wenderlich's tutorial)

I have set up 11 consumables which are in two distinct sets; coins and categories.

What I want to do is have two buttons, each taking the user to a different table. Depending on the table a different set is displayed.

I have tried for hours to get this to work and I cannot do it; so I bow to the powers of the StackOverflow community to help.

Currently my set is as follows:

    NSSet * productIdentifiers = [NSSet setWithObjects:
                                  @"com.ac.scramble.coins1",
                                  @"com.ac.scramble.coins2",
                                  @"com.ac.scramble.coins3",
                                  @"com.ac.scramble.coins4",
                                  @"com.ac.scramble.coins5",
                                   @"com.ac.scramble.category1",
                                   @"com.ac.scramble.category3",
                                   @"com.ac.scramble.category5",
                                   @"com.ac.scramble.category8",
                                   @"com.ac.scramble.category15",
                                   @"com.ac.scramble.category30",
                                   nil];

        sharedInstance = [[self alloc] initWithProductIdentifiers:productIdentifiers

which is set up through iTunes Connect with no problem.

The evident problem here is that in my first nib which wants to show 6 rows, it is showing the final six in the list above (not sure why the final six rather than the first six...). This is fine, but in the second nib, which wants to show 5 rows, it is showing the final five from the list above. I don't want that - I want it to display the top five (the coins).

I've tried splitting the NSSet up into two and passing through but I cannot get that to work. I don't know if I can in the code somewhere specify which rows of the set I want to display. The pertinent code (I believe) which is probably where I need to do some trickery is:

- (void)reload {
_products = nil;
[self.table2 reloadData];
[[RageIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {

    if (success) {
        _products = products;
        [self.table2 reloadData];
    }
    //[self.refreshControl endRefreshing];
}];
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *simpleTableIdentifier = @"SimpleTableCell";


SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];
}

SKProduct *product = (SKProduct *) _products[indexPath.row];

cell.nameLabel.text = product.localizedTitle;
NSLog(@"Localized title: %@", product.localizedTitle);
cell.thumbnailImageView.image = [UIImage imageNamed:[thumbnails3 objectAtIndex:indexPath.row]];
cell.descriptionLabel.text = [descriptions3 objectAtIndex:indexPath.row];

[_priceFormatter setLocale:product.priceLocale];
//cell.detailTextLabel.text = [_priceFormatter stringFromNumber:product.price];
cell.progressLabel.text = [_priceFormatter stringFromNumber:product.price];
cell.descriptionLabel.text = product.localizedDescription;
}

Thanks to all in advance.

Was it helpful?

Solution

I managed to work out the answer and it was indeed splitting the set up. This may not be the most efficient way of doing this but I took the Set of 11 elements and depending on which one I wanted I either used the removeLastObject or removeObjectAtIndex[0] methods to obtain what I wanted. Thanks to everyone's help!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top