Reputation: 3078
I am using this code to pass a object to another view controller.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"Detail"]){
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
DetailedViewController *controller = (DetailedViewController *)navController.topViewController;
controller.clipping = [pasteBoardArray objectAtIndex:_row];
}
}
On the line of:
DetailedViewController *controller = (DetailedViewController *)navController.topViewController;
I get a lengthy exception
2014-05-20 18:46:39.752 SWTableViewCell[8370:60b] -[DetailedViewController topViewController]: unrecognized selector sent to instance 0x10c7169e0
2014-05-20 18:46:39.756 SWTableViewCell[8370:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetailedViewController topViewController]: unrecognized selector sent to instance 0x10c7169e0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102667495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001016c699e objc_exception_throw + 43
2 CoreFoundation 0x00000001026f865d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000102658d8d ___forwarding___ + 973
4 CoreFoundation 0x0000000102658938 _CF_forwarding_prep_0 + 120
5 SWTableViewCell 0x000000010000d91c -[ViewController prepareForSegue:sender:] + 204
6 UIKit 0x00000001004f4c73 -[UIStoryboardSegueTemplate _perform:] + 134
7 SWTableViewCell 0x000000010000c4be -[ViewController tableView:didSelectRowAtIndexPath:] + 350
8 SWTableViewCell 0x00000001000089ae -[SWTableViewCell selectCell] + 798
9 SWTableViewCell 0x000000010000864b -[SWTableViewCell scrollViewTapped:] + 171
10 UIKit 0x0000000100362fc2 _UIGestureRecognizerSendActions + 188
11 UIKit 0x0000000100361f28 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 357
12 UIKit 0x00000001003662d9 ___UIGestureRecognizerUpdate_block_invoke + 53
13 UIKit 0x0000000100366261 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 257
14 UIKit 0x000000010035e337 _UIGestureRecognizerUpdate + 93
15 UIKit 0x0000000100072a15 -[UIWindow _sendGesturesForEvent:] + 928
16 UIKit 0x00000001000736d4 -[UIWindow sendEvent:] + 909
17 UIKit 0x000000010004b29a -[UIApplication sendEvent:] + 211
18 UIKit 0x0000000100038aed _UIApplicationHandleEventQueue + 9579
19 CoreFoundation 0x00000001025f6d21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
20 CoreFoundation 0x00000001025f65f2 __CFRunLoopDoSources0 + 242
21 CoreFoundation 0x000000010261246f __CFRunLoopRun + 767
22 CoreFoundation 0x0000000102611d83 CFRunLoopRunSpecific + 467
23 GraphicsServices 0x00000001025c6f04 GSEventRunModal + 161
24 UIKit 0x000000010003ae33 UIApplicationMain + 1010
25 SWTableViewCell 0x0000000100002763 main + 115
26 libdyld.dylib 0x000000010607f5fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
As a side note I am doing this all within a UINavigationBarController
. All I need to do is pass objectAtIndex:_row
to the _clipping
property in the DetailedViewController
.
Upvotes: 1
Views: 151
Reputation: 92419
Use the following code if there is NO navigation controller BETWEEN your two view controllers:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"Detail"]){
DetailedViewController *controller = (DetailedViewController *)[segue destinationViewController];
controller.clipping = [pasteBoardArray objectAtIndex:_row];
/* ... */
}
}
Use the following code only if there is ONE navigation controller BETWEEN your two view controllers:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"Detail"]){
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
DetailedViewController *controller = (DetailedViewController *)navController.topViewController;
controller.clipping = [pasteBoardArray objectAtIndex:_row];
/* ... */
}
}
Upvotes: 1
Reputation: 131418
The error message you posted suggests that the destination view controller of your segue is not a navigation controller as you think it is. You should log the class of the destination view controller to see what it is.
Upvotes: 0