ios - iOS-UITableViewCell中的UIButton的长按手势识别器

标签 ios objective-c uitableview uigesturerecognizer

我有一个带有3 UITableViewCellUIButton,它用于递减计数器。长按其中一个按钮,我想将计数器设置为0。

在Interface Builder中执行此操作,我将Long Press Gesture Recognizer拖到我的button上,并将选择器连接到IBAction中指定的UITableViewCell.m

这就是我所做的一切,但是当我运行该应用程序时,出现以下错误。

'NSInternalInconsistencyException', 
reason: 'invalid nib registered for identifier (editQuotaCell) 
- nib must contain exactly one top level object which must be a UITableViewCell instance'

我是否缺少任何步骤?

最佳答案

只需在编码中创建按钮,即可添加手势和选择器。它将起作用。检查下面的代码

 -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
     if(cell == nil)
     {
         UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];
         cell.backgroundColor = [UIColor clearColor];
         cell.selectionStyle = UITableViewCellSelectionStyleNone;

         UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
         [btn addTarget:self action:@selector(select_Action:) forControlEvents:UIControlEventTouchUpInside];
         [btn setTag:Selection_Tag];
         [btn setBackgroundImage:[UIImage imageNamed:@"Demo03.png"] forState:UIControlStateNormal];
         [btn setFrame:CGRectMake(0,0,tableView.frame.size.width,tableView.rowHeight)];
         [cell.contentView btn];

        //Add Your gestures here
     }


     return cell;
 }

关于ios - iOS-UITableViewCell中的UIButton的长按手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20878090/

相关文章:

ios - 在 Swift 中使用 NSTimer 查找选择器时出错

ios - 使用适用于 IOS 的 Google Maps SDK 时出现 Apple Mach-O 链接器错误

ios - Swift JavaScriptCore 有时会崩溃(bmalloc::VMHeap::grow())

iphone - 使用泰米尔文本时 UItableview 滚动问题

ios - 解析 saveInBackgroundWithBlock 在 iOS 上崩溃

ios - 如何链接XCODE项目的外部框架

iphone - 当 iPad 方向改变时,UIView 动画行为异常

ios - dequeueReusableCellWithIdentifier :forIndexPath: 中的断言失败

ios - 无法访问自定义表格单元格变量

ios - TableView 仅显示一个单元格 - Swift 3