簡體   English   中英

iOS-UITableViewCell中的UIButton的長按手勢識別器

[英]iOS - Long Press Gesture Recognizer for UIButton in UITableViewCell

我有一個帶有3個UIButtonUITableViewCell ,用於遞減計數器。 長按其中一個按鈕,我想將計數器設置為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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM