2012-11-14 38 views
0

我试图将一个对象从视图控制器传递给另一个。 在destinationController我:使用segue的xcode传递对象

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

在含有的viewController我掌握的信息:

- (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]; 

其中vcArray包含数字和名称,但我只希望选择行。 尝试将所选对象传递给destinationController中的对象似乎不起作用。相反,它给我的错误:

[的viewController copyWithZone:]:无法识别的选择发送到实例0x8000140 2012年11月14日18:08:25.039的应用[3314:13d03] *终止应用程序由于未捕获的异常“NSInvalidArgumentException ”,原因: ' - [的viewController copyWithZone:]:无法识别的选择发送到实例0x8000140' *第一掷调用堆栈: (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:终止调用抛出异常

我觉得问题是,我并没有使用正确的对象

+1

请更新与实际误差显示哪些选择和阶级它在抱怨的问题。 –

回答

1

的问题是在你的财产申报:

@property(nonatomic,copy) destinationController *object; 

这是说,只要你分配一个对象该属性,对象被复制。

但是,正如您的错误消息所述 - 您尚未实施NSCopying协议所需的方法(其中copy来自此处)。

你或许应该改变这种声明:

@property(nonatomic, strong) destinationController *object; 
+0

thx似乎工作。数组包含名称和数字,但如果我使用object.name,它不会找到它。我如何获得姓名和电话号码? –

+0

我不知道你在问什么。 – Abizern

+0

我的意思是如果我写vcArray.name我会在数组中获得名称。现在我已经将它传递给了dC.object,如何从对象中获取名称?我在destinationController NSLog(@“%@”,spsObject.name)中写道;但它没有找到变量名称。 –