Dale Myers
Dale Myers

Reputation: 2821

Detect when user touches a cell in a table

I have some custom cells which are working perfectly. I have a background image on these cells. I would like to change the background image when a users finger touches the cell. It would then change back on the selection of the cell (but that can be done in didSelectRowAtIndexPath).

Does anyone know how to do this?

Thanks.

Upvotes: 0

Views: 227

Answers (2)

ott--
ott--

Reputation: 5702

Start in didSelectRowAtIndexPath, call cellForRowAtIndexPath to retrieve the cell, then you can change the content. It could be that you need [cell setNeedsDisplay];.

Upvotes: 0

Rok Jarc
Rok Jarc

Reputation: 18865

Since you allready have custom cell you can override id touchesBegan: and touchesEnded:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    //change background here...
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{
    [super touchesEnded:touches withEvent:event];
    //restore background here...
}

Note that i didn't test this - hope it wont be just a waste of your time.

Upvotes: 1

Related Questions