我正在尝试通过 IB 进行 segue,当按下 tableView 中的单元格附件时切换视图。
来自我的IB的图片:
1.我从 tableviewcontroller 的单元格拖动到另一个视图并选择 Accessory Action -> Push
当我运行我的项目时出现错误:
[ setValue:forUndefinedKey:]:此类对于关键配件ActionSegueTemplate 不符合键值编码
我认为这可能是单元格的reuseIdentifier有问题。
My cellForRowAtIndexPath:
method:
static NSString *CellIdentifier = @"champion cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSString *cellIconName = ((championList *)[self.champions objectAtIndex:indexPath.row]).championImage;
UIImage *cellIcon = [UIImage imageNamed:cellIconName];
[[cell imageView] setImage:cellIcon];
cell.imageView.frame = CGRectMake(0.0f, 0.0f, 70.0f, 70.0f);
cell.imageView.layer.cornerRadius = 7;
[cell.imageView.layer setMasksToBounds:YES];
cell.textLabel.text = ((championList *) [self.champions objectAtIndex:indexPath.row]).championName;
cell.detailTextLabel.text = ((championList *) [self.champions objectAtIndex:indexPath.row]).championId;
return cell;
我可以使用 PerformSegueWithIdentifier: 方法作为这个问题的解决方案,但我想弄清楚为什么我在 IB 中遇到辅助操作问题。
当我按住 Ctrl 键将 Segue 从原型单元的详细附件按钮拖动到下一个视图控制器时,我遇到了这个问题。因此,我从表视图控制器本身进行拖动,并向其中添加了一些代码。
Objective-C:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier: @"EditUser" sender: [tableView cellForRowAtIndexPath: indexPath]];
}
斯威夫特 3.0:
func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
performSegue(withIdentifier: "EditUser", sender: tableView.cellForRow(at: indexPath))
}
这适用于 iOS 5.0 - 10.x
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)