DisclosureIndicator does not detect touches

杀马特。学长 韩版系。学妹 提交于 2019-12-08 20:03:45

问题


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)


回答1:


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




回答2:


Check out the names of the accessory indicators UITableViewCellAccessoryNone, UITableViewCellAccessoryDisclosureIndicator, UITableViewCellAccessoryDetailDisclosureButton UITableViewCellAccessoryCheckmark, UITableViewCellAccessoryDetailButton

Only detail button and detail disclosure button receives taps and calls the method . U may use UIGestureRecognizer and a custom method .



来源:https://stackoverflow.com/questions/8389314/disclosureindicator-does-not-detect-touches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!