问题描述
我使用 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
应自动调用。
这里是我的代码:
- (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)
推荐答案
推荐答案
答案在你的问题。您说
您在部分
只有当您使用
UITableViewCellAccessoryDetailDisclosureButton
。区别当然是,这是一个按钮, 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不检测触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!