我正在尝试通过 IB 进行 segue,即在 tableView 中按下单元格附件时切换 View 。
来 self 的 IB 的图片:
1.我从 tableviewcontroller 的单元格拖到另一个 View 并选择 Accessory Action -> push
当我运行我的项目时出现错误:
[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key accessoryActionSegueTemplate
我认为这可能是 cell 的 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;
我可以使用 performSegueWithIdentifier: 方法来解决这个问题,但我想弄清楚为什么我在 IB 中的辅助操作有问题。
最佳答案
当我按住 ctrl 键将 segue 从原型(prototype)单元格的细节附件按钮拖到下一个 View Controller 时,我遇到了这个问题。因此,我从 TableView Controller 本身进行了拖动,并向其中添加了一些代码。
Objective-C :
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier: @"EditUser" sender: [tableView cellForRowAtIndexPath: indexPath]];
}
swift 3.0:
func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
performSegue(withIdentifier: "EditUser", sender: tableView.cellForRow(at: indexPath))
}
这适用于 iOS 5.0 - 10.x
关于iphone - 附件 Action segue (UITableViewController),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12617219/