xcode 附属动作转场(UITableViewController)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12617219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
accessory action segue (UITableViewController)
提问by ignotusverum
I'm trying to make segue via IB, that switching views when pressed cell accessory in tableView.
我正在尝试通过 IB 进行切换,即在 tableView 中按下单元格附件时切换视图。
Images from my IB:
来自我的 IB 的图片:
1.I'm dragging from cell of tableviewcontroller to another view and selecting Accessory Action -> push
1.我从tableviewcontroller的单元格拖动到另一个视图并选择附件操作->推送
and when i'm running my project i get error:
当我运行我的项目时,我收到错误:
[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key accessoryActionSegueTemplate
[ setValue:forUndefinedKey:]: 此类不符合关键附件ActionSegueTemplate 的关键值编码
I think that this might be something wrong with reuseIdentifier of cell.
我认为这可能是 cell 的重用标识符有问题。
My cellForRowAtIndexPath:
method:
我的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;
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.
我可以使用 performSegueWithIdentifier: 方法作为这个问题的解决方案,但我想弄清楚为什么我在 IB 中遇到附加操作问题。
回答by mARK
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.
当我按住 ctrl 将 segue 从原型单元格的细节附件按钮拖动到下一个视图控制器时,我遇到了这个问题。因此,我从表视图控制器本身进行了拖动,并为其添加了一些代码。
Objective-C:
目标-C:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier: @"EditUser" sender: [tableView cellForRowAtIndexPath: indexPath]];
}
Swift 3.0:
斯威夫特 3.0:
func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
performSegue(withIdentifier: "EditUser", sender: tableView.cellForRow(at: indexPath))
}
This works for iOS 5.0 - 10.x
这适用于 iOS 5.0 - 10.x
回答by Louis Cremen
I'm getting this error when I run my application on iOS 5 on an iPod Touch and not on iOS 6 on an iPhone 5.
当我在 iPod Touch 上的 iOS 5 上运行我的应用程序而不是在 iPhone 5 上的 iOS 6 上运行我的应用程序时出现此错误。
The docs say that accessory action was deprecated in iOS 3.0. The bug seems to be that it's being shown and allowed in iOS 6.
文档说在 iOS 3.0 中不推荐使用附件操作。该错误似乎是在 iOS 6 中显示和允许的。
Can you confirm what version of iOS you're testing against?
您能否确认您正在测试的 iOS 版本是什么?
回答by Nikolay Spassov
I just ran into the same problem. Works fine on iOS 6, crashes on 5.1.
我刚刚遇到了同样的问题。在 iOS 6 上运行良好,在 5.1 上崩溃。
The way I solved it is by using a standard UITableViewCell
and creating the accessory button out of a UIButton
, on which I put a segue.
我解决它的方法是使用标准UITableViewCell
并从 a 创建附件按钮UIButton
,我在上面放了一个 segue。
回答by JHos
On iOS 5.x, this error also occurs when you create a popover style segue in a storyboard, and (in my case) anchor it to a UITableViewCell.
在 iOS 5.x 上,当您在故事板中创建 popover 样式 segue 并且(在我的情况下)将其锚定到 UITableViewCell 时,也会发生此错误。
In this case, the error message is a completely misleading red herring.
在这种情况下,错误消息完全是误导性的红鲱鱼。
I'm assuming that iOS 5.x doesn't support anchored popover segues.
我假设 iOS 5.x 不支持锚定 popover segues。
回答by Abhishek Sahay
Drag a navigationController from object library to your storyboard file and try to do this, it should work.Your next View should have the navigation controller.
将一个导航控制器从对象库拖到您的故事板文件中并尝试执行此操作,它应该可以工作。您的下一个视图应该具有导航控制器。