UITableViewCell - 发送到实例的无法识别的选择器
UITableViewCell - unrecognized selector sent to instance
我正在尝试实现向左向右滑动,但出现此错误:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '- [UITableViewCell
setDelegate]: unrecognized selector sent to instance 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
子类 MGSwipeTableViewCell
,因此您必须确保从 dequeueReusableCellWithIdentifier
return 返回的单元格是 MGSwipeTableViewCell
.
首先,您可以删除 if (!cell) { ... }
块,因为 dequeueReusableCellWithIdentifier
应该 return 和 UITableViewCell
如果您在 .xib 或故事板上设置了标识符.如果单元格在故事板或 .xib 上没有重用标识符,则拥有额外的块会使此代码更难调试。
接下来,在您尝试出列的单元格存在的 .xib 或情节提要中,select 原型 UITableViewCell
并查看 "Class" 部分下的框 "Custom Class"。将其更改为 MGSwipeTableViewCell
,因为我怀疑它已设置为 UITableViewCell
。这应该可以解决问题。这是 Xcode 我说的区域:
您应该可以设置 cell.delegate 和其他 MGSwipeTableViewCell
属性,在您将一个真正的 MGSwipeTableViewCell
.
出列后
我正在尝试实现向左向右滑动,但出现此错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [UITableViewCell setDelegate]: unrecognized selector sent to instance 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
子类 MGSwipeTableViewCell
,因此您必须确保从 dequeueReusableCellWithIdentifier
return 返回的单元格是 MGSwipeTableViewCell
.
首先,您可以删除 if (!cell) { ... }
块,因为 dequeueReusableCellWithIdentifier
应该 return 和 UITableViewCell
如果您在 .xib 或故事板上设置了标识符.如果单元格在故事板或 .xib 上没有重用标识符,则拥有额外的块会使此代码更难调试。
接下来,在您尝试出列的单元格存在的 .xib 或情节提要中,select 原型 UITableViewCell
并查看 "Class" 部分下的框 "Custom Class"。将其更改为 MGSwipeTableViewCell
,因为我怀疑它已设置为 UITableViewCell
。这应该可以解决问题。这是 Xcode 我说的区域:
您应该可以设置 cell.delegate 和其他 MGSwipeTableViewCell
属性,在您将一个真正的 MGSwipeTableViewCell
.