2012-11-14 40 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)中寫道;但它沒有找到變量名稱。 –