2012-05-12 12 views
1

我練的iPhone開發委託,但有一個問題無法識別的選擇發送到實例0x6b61d10

2012-05-12 21:21:54.279 DelegatePractice [2924:F803] - [secondViewController viewControllers]:無法識別的選擇發送到實例0x6b61d10 2012-05-12 21:21:54.281 DelegatePractice [2924:F803] *終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因: ' - [secondViewController viewControllers]:無法識別的選擇發送到實例0x6b61d10' *第一次調用堆棧: (0x13bb052 0x154cd0a 0x13bcced 0x1321f00 0x1321ce2 0x2596 0x436e1e 0x13bcec9 0x155c2 0x250d54 0x13bcec9 0x155c2 0x1555a 0xbab 76 0xbb03f 0xba2fe 0x3aa30 0x3ac56 0x21384 0x14aa9 0x12a5fa9 0x138f1c5 0x12f4022 0x12f290a 0x12f1db4 0x12f1ccb 0x12a4879 0x12a493e 0x12a9b 0x1e98 0x1df5)

,我想我成立了代表正確:

delegateViewController.m

- (void)secondViewControllerDidJump: 
(secondViewController *)controller 
{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([segue.identifier isEqualToString:@"jump"]) 
    { 
     UINavigationController *navigationController = segue.destinationViewController; 
     secondViewController *SecondViewController =[[navigationController viewControllers]objectAtIndex:0]; 
     SecondViewController.delegate = self; 
    } 
} 

@end 

secondViewController.h

@class secondViewController; 

@protocol SecondViewControllerDelegate <NSObject> 
- (void)secondViewControllerDidJump: (secondViewController *)controller; 

@end 

@interface secondViewController : UITableViewController 

@property (strong,nonatomic) NSArray *choices; 
@property (nonatomic, weak) id <SecondViewControllerDelegate> delegate; 

- (IBAction)jump:(id)sender; 

@end 

secondViewController.m

在這些線路
- (IBAction)jump:(id)sender 
{ 
    [self.delegate secondViewControllerDidJump:self]; 
} 

回答

0

您的應用程序崩潰:

UINavigationController *navigationController = segue.destinationViewController; 
secondViewController *SecondViewController =[[navigationController viewControllers]objectAtIndex:0]; 

你問navigationControllerviewControllers,但日誌明確指出navigationController一個UINavigationControllersecondViewController,不給迴應選擇器-viewControllers

確保segue.destinationViewController確實返回UINavigationController

+0

你能告訴我正確的代碼嗎?因爲我看到它,navigationController是一個UINavigationController,我真的不明白 – oratis

+0

你嘗試記錄它的類像NSLog(@「%@」,[navigationController類])?我不能給你正確的代碼,因爲我從來沒有做過,也從不會與故事板一起工作。 –

+0

我記錄了它,它是2012-05-12 21:53:12.157 DelegatePractice [3250:f803] secondViewController,thst的奇怪,怎麼樣? – oratis

0

試試這個

secondViewController *SecondViewController =[[self.navigationController viewControllers]objectAtIndex:0]; 
1

有同樣的問題,我解決了使用:

secondViewController *SecondViewController = segue.destinationViewController; 

基本上segue.destinationViewController返回一個視圖控制器,所以用它。

相關問題