辅助动作segue(UITableViewController) [英] accessory action segue (UITableViewController)

查看:114
本文介绍了辅助动作segue(UITableViewController)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to make segue via IB, that switching views when pressed cell accessory in tableView.

来自我的IB的图像:

1.我从tableviewcontroller的单元格拖到另一个视图并选择附件操作 - >推送

1.I'm dragging from cell of tableviewcontroller to another view and selecting Accessory Action -> push

当我运行我的项目时出现错误:

and when i'm running my project i get error:


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

[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key accessoryActionSegueTemplate

我认为这可能是单元格的reuseIdentifier出错了。

I think that this might be something wrong with reuseIdentifier of cell.

我的 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有配件行动的问题。


I can use performSegueWithIdentifier: method as solution of this problem, but i want to figure out why i having problem with accessory action in IB.

推荐答案

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

I had this problem when I had ctrl-dragged a segue from the detail accessory button of the prototype cell to the next view controller. So instead I did the drag from the table view controller itself, and added a bit of code to it.

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

This works for iOS 5.0 - 10.x

这篇关于辅助动作segue(UITableViewController)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆