我有一个带有3 UITableViewCell
的UIButton
,它用于递减计数器。长按其中一个按钮,我想将计数器设置为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/