【问题标题】:UITableViewCell - unrecognized selector sent to instanceUITableViewCell - 发送到实例的无法识别的选择器
【发布时间】:2015-09-09 12:53:10
【问题描述】:

我正在尝试向左滑动,但出现此错误:

由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'- [UITableViewCell setDelegate]: 无法识别的选择器发送到实例 0x7fbadb85d710'

这行错误:

cell.delegate = self;
cell.allowsMultipleSwipe = allowMultipleSwipe;
cell.rightSwipeSettings.transition = data.transition;
cell.rightExpansion.buttonIndex = data.rightExpandableIndex;
cell.rightExpansion.fillOnTrigger = YES;
cell.rightButtons = [self createRightButtons:data.rightButtonsCount];

我的代码:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
     {
         MGSwipeTableCell *cell ;
         static NSString * reuseIdentifier = @"listAlbuns";
         cell = [self.tblAlbum dequeueReusableCellWithIdentifier:reuseIdentifier];
         if (!cell) {
             cell = [[MGSwipeTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
         }

         NSString *sectionTitle = [albumSectionTitles objectAtIndex:indexPath.section];
         NSMutableDictionary *sectionAlbuns = [albuns objectForKey:sectionTitle];
         NSString *title = [sectionAlbuns objectForKey: [NSString stringWithFormat:@"%i", indexPath.row]];
         NSMutableDictionary *album = [baseController getCurrentItemByTitle: albunsBD :title];

         TestData *data = [tests objectAtIndex:indexPath.row];
         NSInteger ID = [album objectForKey: @"1"];
         cell.textLabel.text = [album objectForKey: @"2"];
         cell.detailTextLabel.text = [[albumDAO selectArtistByAlbumID: ID] uppercaseString];
         cell.imageView.image = [UIImage imageNamed: @"icones-categorias-album"];
         cell.imageView.image = [albumDAO getThumb: ID];

         cell.tag = [album objectForKey: @"1"];
         cell.delegate = self;
         cell.allowsMultipleSwipe = allowMultipleSwipe;
         cell.rightSwipeSettings.transition = data.transition;
         cell.rightExpansion.buttonIndex = data.rightExpandableIndex;
         cell.rightExpansion.fillOnTrigger = YES;
         cell.rightButtons = [self createRightButtons:data.rightButtonsCount];

         return cell;
     }

有人知道什么是可能的吗?

【问题讨论】:

  • 你使用 UITableViewCell 的自定义子类吗?如果没有,请删除该行 cell.delegate = self;因为 UITableViewCell 的实例没有委托。
  • 尝试用(MGSwipeTableCell*)[self.tblAlbum dequeueReusableCellWithIdentifier:reuseIdentifier];替换[self.tblAlbum dequeueReusableCellWithIdentifier:reuseIdentifier];
  • 我使用自定义子类。你说的我试过了,但没有解决
  • 这个“allowsMultipleSwipe”有什么作用?
  • 控制是否可以同时滑动多个单元格

标签: ios objective-c uitableview swipe


【解决方案1】:

由于您尝试使用UITableViewCell 子类MGSwipeTableViewCell,因此您必须确保从dequeueReusableCellWithIdentifier 返回的单元格返回MGSwipeTableViewCell

首先,您可以删除if (!cell) { ... } 块,因为如果您在.xib 或情节提要中设置了标识符,dequeueReusableCellWithIdentifier 应该返回UITableViewCell。如果单元格在情节提要或 .xib 上没有重用标识符,则拥有额外的块会使此代码更难调试。

接下来,在您的 .xib 或情节提要中,您尝试出列的单元格所在的位置,选择原型 UITableViewCell 并查看“自定义类”部分下名为“类”的框。将其更改为MGSwipeTableViewCell,因为我怀疑它设置为UITableViewCell。这应该可以解决问题。这是我正在谈论的 Xcode 中的区域:

你应该能够设置 cell.delegate 和其他 MGSwipeTableViewCell 属性后你出列一个真正的MGSwipeTableViewCell

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 2012-07-24
    相关资源
    最近更新 更多