Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessory action segue (UITableViewController)

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

Images from my IB:

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

IB screenshot

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

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

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

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;

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.

like image 351
ignotusverum Avatar asked Sep 27 '12 08:09

ignotusverum


4 Answers

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))
}

This works for iOS 5.0 - 10.x

like image 150
mARK Avatar answered Oct 03 '22 03:10

mARK


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.

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.

Can you confirm what version of iOS you're testing against?

https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableViewCell_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instp/UITableViewCell/accessoryAction

like image 39
Louis Cremen Avatar answered Oct 03 '22 01:10

Louis Cremen


I just ran into the same problem. Works fine on iOS 6, crashes on 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.

like image 42
Nikolay Spassov Avatar answered Oct 03 '22 01:10

Nikolay Spassov


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.

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.

like image 28
JHos Avatar answered Oct 03 '22 01:10

JHos