Jim
Jim

Reputation: 9234

Iphone: UITableView how to detect that row is selected

I have a UITableView, and I press the row, but do not release finger, so didSelectRowAtIndexPath is not called yet, right?

  1. How to detect on which row i clicked? in which method?
  2. How to detect that I clicked on table view? Is there any method like rowIsPressed? or onTableViewTouchDown?

Upvotes: 1

Views: 1030

Answers (3)

calimarkus
calimarkus

Reputation: 9977

There are two options at least:

1) You can subclass UITableViewCell and than use the touchhandling you know from a default uiview. (Like touchesBegan: etc.) / OR add a custom uiview as contentView of the tablecell.

2) Add a gesturerecognizer to each tablecell.

To find out in which row you are, you could give every row a tag (which than refers to the row) in cellForRow:atIndexPath:

Upvotes: 2

There is no such method to detect the selected state before lifting the finger... I guess you should override the UITableView class and add a UIGestureRecognizer to it. And about your second question, I think you are talking about this table view delegate method:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

But there is also another method that will give you the current selected row. This is it (directly from the table view class):

- (NSIndexPath *)indexPathForSelectedRow

Hope to have helped!

Upvotes: 0

Chakalaka
Chakalaka

Reputation: 2827

try this

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath         *)indexPath

Upvotes: 0

Related Questions