[英]iOS - Long Press Gesture Recognizer for UIButton in UITableViewCell
我有一个带有3个UIButton
的UITableViewCell
,用于递减计数器。 长按其中一个按钮,我想将计数器设置为0。
在Interface Builder中执行此操作,将Long Press Gesture Recognizer
拖到我的button
,并将选择器连接到UITableViewCell.m
指定的IBAction
。
这就是我所做的一切,但是当我运行该应用程序时,出现以下错误。
'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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.