Saphrosit Saphrosit - 6 months ago 19
Objective-C Question

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)

Answer

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).