辅助动作segue(UITableViewController)

ign*_*rum 17 iphone xcode objective-c uitableview ios

我正在尝试通过IB制作segue,在tableView中按下单元格附件时切换视图.

来自我IB的图片:

1.我从tableviewcontroller的单元格拖动到另一个视图并选择Accessory Action - > push

IB截图

当我运行我的项目时,我得到错误:

[setValue:forUndefinedKey:]:此类不是密钥值编码兼容的关键附件ActionSegueTemplate

我认为这可能与单元格的reuseIdentifier有关.

我的cellForRowAtIndexPath:方法:

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;
Run Code Online (Sandbox Code Playgroud)

我可以使用performSegueWithIdentifier:方法作为此问题的解决方案,但我想弄清楚为什么我在IB中遇到辅助操作问题.

小智 27

当我从原型单元格的细节附件按钮中拖动一个segue到下一个视图控制器时,我遇到了这个问题.所以我改为从表视图控制器本身进行拖动,并为其添加了一些代码.

Objective-C的:

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier: @"EditUser" sender: [tableView cellForRowAtIndexPath: indexPath]];
}
Run Code Online (Sandbox Code Playgroud)

Swift 3.0:

func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
    performSegue(withIdentifier: "EditUser", sender: tableView.cellForRow(at: indexPath))
}
Run Code Online (Sandbox Code Playgroud)

这适用于iOS 5.0 - 10.x.

  • 这就是答案.附件动作序列只有iOS 6.0+,所以如果你在StoryBoard中有其中一个,那么它会在之前的iOS上用`accessoryActionSegueTemplate`错误轰炸出来 (2认同)