发送到实例0x6b61d10的无法识别的选择器 [英] unrecognized selector sent to instance 0x6b61d10
问题描述
2012-05-12 21:21:54.279 DelegatePractice [2924:f803] - [secondViewController viewController] :无法识别的选择器发送到实例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 0xbab76 0xbb03f 0xba2fe 0x3aa30 0x3ac56 0x21384 0x14aa9 0x12a5fa9 0x138f1c5 0x12f4022 0x12f290a 0x12f1db4 0x12f1ccb 0x12a4879 0x12a493e 0x12a9b 0x1e98 0x1df5)
我想我正确地设置了委托:
delegateViewController。 m
- (void)secondViewControllerDidJump:
(secondViewController *)co ntroller
{
[self dismissViewControllerAnimated:YES completion:nil];
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@jump ])
{
UINavigationController * navigationController = segue.destinationViewController;
secondViewController * SecondViewController = [[navigationController viewControllerers] objectAtIndex:0];
SecondViewController.delegate = self;
}
}
@end
secondViewController .h
@class secondViewController;
@protocol SecondViewControllerDelegate< NSObject>
- (void)secondViewControllerDidJump:(secondViewController *)controller;
@end
@interface secondViewController:UITableViewController
@property(强,非原子)NSArray *选项;
@property(nonatomic,weak)id< SecondViewControllerDelegate>代表;
- (IBAction)jump:(id)sender;
@end
secondViewController.m
- (IBAction)jump:(id)sender
{
[self.delegate secondViewControllerDidJump:self];
}
您的应用程序在这些行中崩溃:
UINavigationController * navigationController = segue.destinationViewController;
secondViewController * SecondViewController = [[navigationController viewControllerers] objectAtIndex:0];
您要求 navigationController
$ c> viewControllers ,但日志显示 navigationController
是不一个 UINavigationController
而是 secondViewController
,它不会响应选择器 -viewControllers
。
确保 segue.destinationViewController
真的返回一个 UINavigationController
。 p>
I am practicing delegate in iphone development but have a problem
2012-05-12 21:21:54.279 DelegatePractice[2924:f803] -[secondViewController viewControllers]: unrecognized selector sent to instance 0x6b61d10 2012-05-12 21:21:54.281 DelegatePractice[2924:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[secondViewController viewControllers]: unrecognized selector sent to instance 0x6b61d10' * First throw call stack: (0x13bb052 0x154cd0a 0x13bcced 0x1321f00 0x1321ce2 0x2596 0x436e1e 0x13bcec9 0x155c2 0x250d54 0x13bcec9 0x155c2 0x1555a 0xbab76 0xbb03f 0xba2fe 0x3aa30 0x3ac56 0x21384 0x14aa9 0x12a5fa9 0x138f1c5 0x12f4022 0x12f290a 0x12f1db4 0x12f1ccb 0x12a4879 0x12a493e 0x12a9b 0x1e98 0x1df5)
and I think I set up the delegate properly:
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];
}
Your app crashes in these lines:
UINavigationController *navigationController = segue.destinationViewController;
secondViewController *SecondViewController =[[navigationController viewControllers]objectAtIndex:0];
You ask navigationController
for its viewControllers
, but the log makes clear that navigationController
is not a UINavigationController
but a secondViewController
, which does not respond to the selector -viewControllers
.
Make sure that segue.destinationViewController
really returns a UINavigationController
.
这篇关于发送到实例0x6b61d10的无法识别的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!