views:

69

answers:

1

Hey all,

How can I give a tableView cell background color the fade effect as soon as it appears. I know how to get a cell selected when the table view appears but the color persists for ever. I would like it to stay there for a while (2 seconds or whatever) and then fade away. Can anyone help me with this?

Off the top of my head, I am thinking NSTimer could be called into use here. What do the experts have to say?

A: 

Forget about timers, they are just too much work in this case. Just make a deselectSelectedCell method and call it using an asynchronous call:

    [tableView performSelector:@selector(deselectSelectedCell) withObject:nil afterDelay:2.0];

and the method:

- (void)deselectSelectedCell{
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES]
}

This will deselect the cell, off course. If you want you cell to remain selected, probably you should change the color of the contentView .

nacho4d
how can we change the color of content view to give that fading look
Bogus Boy
hey nacho4d, my application is crashing with this code. (unrecognized selector sent)
Bogus Boy
What's an asynchronous call. I think it's crashing because of the withObject:nil argument. What's seems to be the problem?\
Bogus Boy
-(void) viewDidAppear:(BOOL)animated{ [table performSelector:@selector(deselectSelectedCell) withObject:nil afterDelay:2.0]; }-(void) deselectSelectedCell { NSLog(@"deselect"); [table deselectRowAtIndexPath:[table indexPathForSelectedRow] animated:YES]; }
Bogus Boy
That should work. I use that way very often: if you want to do [A method:B] after 2.0 seconds just call [A performSelector:@selector(method:) withObject:B afterDelay:2.0]; In this case since deselectSelectedCell has no arguments we pass nil.
nacho4d
Also make sure you don't miss spell the name of the method you want to call. Probably that is the reason you are having crashes.
nacho4d