2

How can I unselect a UITableViewCell when UITableView has scrolled?

Sheehan Alam
  • 57,155
  • 123
  • 348
  • 546

2 Answers2

4

I would imagine you could use the following answer:

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?

Community
  • 1
  • 1
abelito
  • 1,053
  • 1
  • 7
  • 16
  • I'm already using - (void)scrollViewDidScroll:(UIScrollView *)scrollView how can I include my UITableView as well? – Sheehan Alam Jul 24 '10 at 05:25
  • 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 Jul 24 '10 at 09:13
0

You could use the following line in cellForRowAtIndexPath to unselect row after table view will be scrolled:

[_tableView selectRowAtIndexPath:0 animated:NO scrollPosition: UITableViewScrollPositionNone];

Bleeding Fingers
  • 6,210
  • 7
  • 41
  • 68
Pourang
  • 1
  • 1