0

I am trying to pass an object from a view controller to another one. In the destinationController I have:

@interface destinationController : UITableViewController{
    destinationController *object;
@property(nonatomic,copy) destinationController *object;

In the viewController containing the information I have:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
[self performSegueWithIdentifier:@"destinationController" sender:self];

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"destinationController"])
{
    destinationController *dC =[segue destinationViewController];
    NSInteger selected = [[self.tableView indexPathForSelectedRow] row];
    dC.object=[vcArray objectAtIndex:selected];

where the vcArray contains numbers and names but I only want the selected row. Trying to pass the selected object to the object in destinationController does not seem to work. Instead it gives me the error:

[viewController copyWithZone:]: unrecognized selector sent to instance 0x8000140 2012-11-14 18:08:25.039 app[3314:13d03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[viewController copyWithZone:]: unrecognized selector sent to instance 0x8000140'* First throw call stack: (0x18e6012 0x12abe7e 0x19714bd 0x18d5bbc 0x18d594e 0x12a8cc9 0x83b2 0x5c22 0x63aac7 0x2d5422 0x5a68 0x2a28d5 0x2a2b3d 0xca9e83 0x18a5376 0x18a4e06 0x188ca82 0x188bf44 0x188be1b 0x1dae7e3 0x1dae668 0x1f365c 0x1f4d 0x1e75) libc++abi.dylib: terminate called throwing an exception

I think the problem is that I am not assigning properly the object

J-K
  • 139
  • 11

1 Answers1

1

The problem is in your property declaration:

@property(nonatomic,copy) destinationController *object;

This says that whenever you assign an object to this property, the object is copied.

But, as your error message says - you haven't implemented the methods required by the NSCopying protocol (which is where copy comes from).

You probably should change this declaration to:

@property(nonatomic, strong) destinationController *object;
Abizern
  • 146,289
  • 39
  • 203
  • 257
  • thx that seems to work. Array includes name and number but if I use object.name it does not find it. How can I get the name and number? – J-K Nov 14 '12 at 17:32
  • I have no idea what you are asking about. – Abizern Nov 14 '12 at 17:33
  • I mean if I write vcArray.name I will get the name in the array. Now that I have pass it in the dC.object how can I get the name from the object? I wrote in the destinationController NSLog(@"%@",spsObject.name); but it does not find variable name. – J-K Nov 14 '12 at 17:40
  • 1
    I still don't understand what you are asking. `vcArray` is an NSArray (I presume, since you are sending it an `objectAtIndex:` method. An array doesn't have a `name` property, so what you are saying doesn't make sense. – Abizern Nov 14 '12 at 17:59
  • I was referring to the 'name' variable of my vcArray but never mind I will search for it. Thank you again for the answer – J-K Nov 14 '12 at 18:06