views:

228

answers:

1

Hi!

I have a simple grouped UITableView fed from a couple of arrays. Changing the selected text color is no issue, using the cell.selectedTextColor method. But this results in the same color being applied no matter which cell I select. I would, for example, want the text in cell 2 to turn green upon selection, while the text of all the other cells should become red. Is there any way to accomplish this?

Can I use didSelectRowAtIndexPath for this? If so is the case, how?

Cheers, Adam, Sweden

A: 

You may want to take out a couple things but I got this here.

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

    NSInteger row = [indexPath row];

    switch (indexPath.section) 
    {
        case 0:
            switch (row)
            {
                case 0:
                    //Do something amazing
                    break;
                case 1:
                    //Do something amazing
                    break;
                case 2:
                    //Do something amazing
                    break;
                default:
                    //Do something amazing if nothing else will
                    break;
            }
            break;
        case 1:
            //Do something amazing
            break;
        default:
                    //Do something else amazing
            break;
    }
Jaba
Yey! It works! Thank you very much, Jaba. Now i just have to figure out how to make it manageable when you need many cases...
Adam Persson