views:

27

answers:

1

I would like to reload a table view conditionally based on the value of a segmented control, when a button is tapped.

So in my buttonTapped method, i have this code which randomly selects an array item. In the else block i would like to remove the selected item from the array to prevent the same item being selected again, currently I remove it from the array...

But i would like the ability to return the app to the state before the button was tapped, perhaps by making a -mutableCopy of the array and then removing the item from that.

What potential options do i have to indicate that an item cannot be selected again? Grayed out? Color change? Remove row?

    if (selectionControl.selectedSegmentIndex == 0) {
        int r = arc4random() % [[[APP_DELEGATE itemsDictionary] objectForKey:category] count];
        NSLog(@"%i",[[[APP_DELEGATE itemsDictionary] objectForKey:category] objectAtIndex:r]);
    } else {
        //copyOfArray = [APP_DELEGATE.....]mutableCopy]; // Maybe?
        int r = arc4random() % [[[APP_DELEGATE itemsDictionary] objectForKey:category] count];
        NSLog(@"%i",[[[APP_DELEGATE itemsDictionary] objectForKey:category] objectAtIndex:r]);
    }
    [[[APP_DELEGATE itemsDictionary] objectForKey:category] removeObjectAtIndex:r];


    //[copyOfArray removeObjectAtIndex:r]; // Maybe?
    [self.tableView reloadData];
}

In each of the tableView methods i would need to check the state of the selectionControl before returning the value from either the APP_DELEGATE or the copy.

Thanks.

A: 

I think what I'd do is access the "textLabel" member of the UITableCellView, and set the text color to grey.

You can them implement tableView:willSelectRowAtIndexPath: to return NIL when that row is pressed - which will make it so that row cannot actually be selected.

Brad