ios - 自定义单元格和 dequeueCellWithIdentifier 中的 UIGestureRecognizer 冲突

标签 ios objective-c uitableview

我在 UITableView 中注册了一个自定义 UITableViewCell(.h、.m、.xib)。

现在我需要在单元格内使用自定义 UIImage 并将手势识别器附加到它(我不能使用 UIButton)。问题是如果它在运行时我得到一个

Terminating app due to uncaught exception  'NSInternalInconsistencyException', 
reason: 'invalid nib registered for identifier (CustomCell) - 
nib must contain exactly one top level object which must be a UITableViewCell instance'

如果我删除了单元格正常工作的手势,我相信这是一个 cocoa 错误,我现在将尝试以编程方式实例化它,但我想问题在于手势识别器与xib

enter image description here

您知道其他界面构建器解决方法吗?

最佳答案

在 UIImage 和上启用用户交互 在 awakeFromNib 作品中以编程方式添加手势识别器

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImageTap:)];
tap.cancelsTouchesInView = YES;
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[self.imagePicture addGestureRecognizer:tap];

但我想知道它不起作用的原因。我会等待接受。

关于ios - 自定义单元格和 dequeueCellWithIdentifier 中的 UIGestureRecognizer 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31965341/

相关文章:

ios - NSURLConnection sendSynchronousRequest 响应因凭证无效而为零

ios - MFMessageComposeViewController 打开彩信编辑而不是短信和 'buddy name' 文本而不是电话号码

ios - 如何在 UITableView 中删除带有计时器的自定义单元格?

ios - 分页UITableView,设置内容偏移量

ios - TableView 中的自动布局问题

ios - 我想在不使用任何第三方框架的情况下将过滤器应用于录制的视频。我曾尝试将 CIfilter 用于 CAlayer 但它不起作用

ios - 当我的 UITableViewCell 的内容发生变化时,我如何告诉它 "auto-resize"?

iphone - objective-c 对 NSStrings 的 NSMutableSet 进行排序?

objective-c - C和Objective-C中返回地址的内存分配

ios - Swift - 将核心数据检索到自定义单元格