views:

94

answers:

1

How can I unselect a UITableViewCell when UITableView has scrolled?

+1  A: 

I would imagine you could use the following answer:

http://stackoverflow.com/questions/1587855/detecting-uitableview-scrolling

Make sure your .h file looks similar to the following:

@interface ItemSelectController : UITableViewController <UIScrollViewDelegate> {

Then place the following in your .m to detect when scrolling occurs and deselect whatever cell is selected.

-(void) scrollViewDidScroll:(UITableView *)sender {
    [sender deselectRowAtIndexPath:[sender indexPathForSelectedRow] animated:YES];
}

The UIScrollViewDelegate in those funny brackets at the end means it implements that protocol. Meaning you have access to functions like scrollViewDidScroll. The top function up there overrides it to do what you want. You wouldn't happen to have multi-select on, would you?

abelito
I'm already using - (void)scrollViewDidScroll:(UIScrollView *)scrollView how can I include my UITableView as well?
Sheehan Alam
I am not sure what you mean by include your UITableView. Can you clarify? The answer makes it so that when your UITableView scrolls it sends a message to your Controller, which then deselects everything. See at the end of the first line of the second code block, it says: (UITableView *) sender ?
abelito