DisclosureIndicator不检测触摸 [英] DisclosureIndicator does not detect touches

查看:246
本文介绍了DisclosureIndicator不检测触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 UITableViewCellAccessoryDisclosureIndicator 作为 accessoryType 我的 UITableViewCell 。根据Apple的文档,数据源方法

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 

应自动调用。


如果启用单元格并且附件类型为UITableViewCellAccessoryDe​​tailDisclosureButton,则附件视图会跟踪触摸,并在点击时向数据源对象发送tableView:accessoryButtonTappedForRowWithIndexPath:message。

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.

这里是我的代码:

- (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;
}

数据源方法只是一个 NSLog 但没有打印...

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)

推荐答案

答案在你的问题。您说


我使用UITableViewCellAccessoryDisclosureIndicator作为
accessoryType ...

I am using UITableViewCellAccessoryDisclosureIndicator as accessoryType ...

您在部分


如果启用单元格, UITableViewCellAccessoryDe​​tailDisclosureButton ...

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

只有当您使用 UITableViewCellAccessoryDe​​tailDisclosureButton 。区别当然是,这是一个按钮, UITableViewCellAccesssoryDisclosureIndicator 不是。当你使用后者,点击它就像点击单元格本身。您可以创建一个自定义单元格并实现 hitTest:来确定轻敲是否接近公开指示符,但似乎比必要的更多的工作(除非您<真的不想使用详细信息按钮)。

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

这篇关于DisclosureIndicator不检测触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆