Question

I've been trying to pass variables between view controllers without much luck. I started to work backwards from the problem I was encountering but am now having problems just getting the segue to action.

Whether I perform the segue with identifier method or have it actioning from the button I am using to perform a calculation I get the below error in the debugger.

Any help would be appreciated.

2014-02-14 13:59:58.795 BatteryCalculator[6944:70b] Cannot find executable for CFBundle 0x8dbd110 </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/AccessibilityBundles/CertUIFramework.axbundle> (not loaded)
2014-02-14 14:00:00.869 BatteryCalculator[6944:70b] -[DetectorSpacing _setViewDelegate:]: unrecognized selector sent to instance 0x8dd6ff0
2014-02-14 14:00:00.872 BatteryCalculator[6944:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetectorSpacing _setViewDelegate:]: unrecognized selector sent to instance 0x8dd6ff0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0173d5e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x014c08b6 objc_exception_throw + 44
    2   CoreFoundation                      0x017da903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0172d90b ___forwarding___ + 1019
    4   CoreFoundation                      0x0172d4ee _CF_forwarding_prep_0 + 14
    5   UIKit                               0x00347ecc +[UIViewController setViewController:forView:] + 40
    6   UIKit                               0x00342921 -[UIViewController setView:] + 511
    7   Foundation                          0x010edd28 _NSSetUsingKeyValueSetter + 133
    8   Foundation                          0x010ed253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
    9   Foundation                          0x0114f70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
    10  UIKit                               0x004d0a15 -[UIRuntimeOutletConnection connect] + 106
    11  libobjc.A.dylib                     0x014d27d2 -[NSObject performSelector:] + 62
    12  CoreFoundation                      0x01738b6a -[NSArray makeObjectsPerformSelector:] + 314
    13  UIKit                               0x004cf56e -[UINib instantiateWithOwner:options:] + 1417
    14  UIKit                               0x00341605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
    15  UIKit                               0x00341dad -[UIViewController loadView] + 302
    16  UIKit                               0x003420ae -[UIViewController loadViewIfRequired] + 78
    17  UIKit                               0x003425b4 -[UIViewController view] + 35
    18  UIKit                               0x0035c3e2 -[UINavigationController _startCustomTransition:] + 778
    19  UIKit                               0x003690c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
    20  UIKit                               0x00369cb9 -[UINavigationController __viewWillLayoutSubviews] + 57
    21  UIKit                               0x004a3181 -[UILayoutContainerView layoutSubviews] + 213
    22  UIKit                               0x0ecdc56f -[UILayoutContainerViewAccessibility(SafeCategory) layoutSubviews] + 50
    23  UIKit                               0x00299267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    24  libobjc.A.dylib                     0x014d281f -[NSObject performSelector:withObject:] + 70
    25  QuartzCore                          0x03b4b2ea -[CALayer layoutSublayers] + 148
    26  QuartzCore                          0x03b3f0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    27  QuartzCore                          0x03b3ef40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    28  QuartzCore                          0x03aa6ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    29  QuartzCore                          0x03aa7e71 _ZN2CA11Transaction6commitEv + 393
    30  QuartzCore                          0x03aa8544 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    31  CoreFoundation                      0x017054ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    32  CoreFoundation                      0x0170541f __CFRunLoopDoObservers + 399
    33  CoreFoundation                      0x016e3344 __CFRunLoopRun + 1076
    34  CoreFoundation                      0x016e2ac3 CFRunLoopRunSpecific + 467
    35  CoreFoundation                      0x016e28db CFRunLoopRunInMode + 123
    36  GraphicsServices                    0x036e29e2 GSEventRunModal + 192
    37  GraphicsServices                    0x036e2809 GSEventRun + 104
    38  UIKit                               0x0022ed3b UIApplicationMain + 1225
    39  BatteryCalculator                   0x0000582d main + 141
    40  libdyld.dylib                       0x01d7b70d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

At the moment I'm not trying to pass anything, I took that code out temporarily while trying to locate the problem. All I'm doing is calling a segue with identifier and getting the crash. I've also tried just calling the segue from a button on the first view controller but the same error.

When calling the segue with code I was using:

[self performSegueWithIdentifier:@"ResultSegue" sender:sender];

Was it helpful?

Solution

Here is how I pass managedObjectContext between segues

In your class where you will pass the data use prepareForSegue call. (The assumption is this class has a variable called _managedObjectContext which can be passed along to the segue class)

Class to Segue From:

.h file:

@property (weak, nonatomic) NSManagedObjectContext *managedObjectContext;

.m file:

@synthesize managedObjectContext

The call to @synthesize will make the following:

  • a local variable called _managedObjectContext
  • a method to getManagedObjectContext
  • a method to setManagedObjectContext

Additionally add the following method to your class

// Pass on managedObjectContext
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

// If the destination VC is able to take the setManagedObjectContext method the current objectContext will be passed along.
if ([segue.destinationViewController respondsToSelector:@selector(setManagedObjectContext:)]) {
    [segue.destinationViewController performSelector:@selector(setManagedObjectContext:)
                                          withObject:_managedObjectContext];
} else {

    NSLog(@"Segue to controller [%@] that does not support passing managedObjectContext", [segue destinationViewController]);
 }
}

Then in my "class" to receive the data I do: in the .h file i have

@property (weak, nonatomic) NSManagedObjectContext *managedObjectContext;

and in the .m file i have:

@synthesize managedObjectContext;

What this does (with syntehsiation) is make a setManagedObjectContext and getManagedObjectContext call. Upon being about to segue I check to make sure the destinationController will "respond to" this method, if so the data gets set.

clear?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top