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)
The answer is in your question. You said
and you quoted the Apple docs in part
Only when you use
UITableViewCellAccessoryDetailDisclosureButtonis the delegate method called. The difference, of course, is that this is a button, whereUITableViewCellAccesssoryDisclosureIndicatoris not. When you use the latter, tapping it is like tapping the cell itself. You could create a custom cell and implementhitTest: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).