Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DisclosureIndicator does not detect touches

I am using UITableViewCellAccessoryDisclosureIndicator as accessoryType of my UITableViewCell. According to Apple's documentation, the data source method

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

should automatically get called.

If the cell is enabled and the accessory type is UITableViewCellAccessoryDetailDisclosureButton, the accessory view tracks touches and, when tapped, sends the data-source object a tableView:accessoryButtonTappedForRowWithIndexPath: message.

here's my code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[cell.textLabel setText:[datasource objectAtIndex:indexPath.row]];

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;
}

The data source method is just a NSLog but nothing is printed...

Am I missing something? (of course, data source and delegate are set properly)

like image 702
Manlio Avatar asked Dec 05 '11 17:12

Manlio


1 Answers

The answer is in your question. You said

I am using UITableViewCellAccessoryDisclosureIndicator as accessoryType ...

and you quoted the Apple docs in part

If the cell is enabled and the accessory type is UITableViewCellAccessoryDetailDisclosureButton ...

Only when you use UITableViewCellAccessoryDetailDisclosureButton is the delegate method called. The difference, of course, is that this is a button, where UITableViewCellAccesssoryDisclosureIndicator is not. When you use the latter, tapping it is like tapping the cell itself. You could create a custom cell and implement hitTest: to determine if the tap was "near" the disclosure indicator, but that seems like more work than necessary (unless you really don't want to use a detail disclosure button).

like image 195
Mark Granoff Avatar answered Oct 03 '22 23:10

Mark Granoff