문제

i have a segmented control which, depending on what is selected, is meant to allocate a value to a NS string, as follows:

-(IBAction)driverKnownIndexChanged{
    switch (self.driverKnown.selectedSegmentIndex) {
        case 0:
            driverKnownResponse = @"Yes";
            break;

        case 1:
            driverKnownResponse = @"No";
            break;
        default:
            break;
    }
}

however, it is throwing a SIGABRT at the following line:

#import "RoadSafetyAppAppDelegate.h"

int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([RoadSafetyAppAppDelegate class]));
    }
}

and here is the console output:

2014-01-30 13:32:16.403 Road Safety App V2[3873:70b] -[DobInAHoonViewController driverKnown:]: unrecognized selector sent to instance 0xcd23440
2014-01-30 13:32:16.409 Road Safety App V2[3873:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DobInAHoonViewController driverKnown:]: unrecognized selector sent to instance 0xcd23440'
*** First throw call stack:
(
    0   CoreFoundation                      0x01d8f7e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01b0f8e5 objc_exception_throw + 44
    2   CoreFoundation                      0x01e2c843 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x01d7fb0b ___forwarding___ + 1019
    4   CoreFoundation                      0x01d7f6ee _CF_forwarding_prep_0 + 14
    5   libobjc.A.dylib                     0x01b2182b -[NSObject performSelector:withObject:] + 70
    6   UIKit                               0x007d8309 -[UIApplication sendAction:to:from:forEvent:] + 108
    7   UIKit                               0x007d8295 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    8   UIKit                               0x008d90a1 -[UIControl sendAction:to:forEvent:] + 66
    9   UIKit                               0x008d9496 -[UIControl _sendActionsForEvents:withEvent:] + 577
    10  UIKit                               0x008d90d6 -[UIControl sendActionsForControlEvents:] + 48
    11  UIKit                               0x00947572 -[UISegmentedControl _setSelectedSegmentIndex:notify:animate:] + 598
    12  UIKit                               0x009498c3 -[UISegmentedControl touchesEnded:withEvent:] + 175
    13  UIKit                               0x00b6ccc3 _UIGestureRecognizerUpdate + 7166
    14  UIKit                               0x008177ca -[UIWindow _sendGesturesForEvent:] + 1291
    15  UIKit                               0x008186e1 -[UIWindow sendEvent:] + 1021
    16  UIKit                               0x007ea542 -[UIApplication sendEvent:] + 242
    17  UIKit                               0x007d42f3 _UIApplicationHandleEventQueue + 11455
    18  CoreFoundation                      0x01d18d7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    19  CoreFoundation                      0x01d1870b __CFRunLoopDoSources0 + 235
    20  CoreFoundation                      0x01d357ae __CFRunLoopRun + 910
    21  CoreFoundation                      0x01d34fd3 CFRunLoopRunSpecific + 467
    22  CoreFoundation                      0x01d34deb CFRunLoopRunInMode + 123
    23  GraphicsServices                    0x0344f4ed GSEventRunModal + 192
    24  GraphicsServices                    0x0344f32a GSEventRun + 104
    25  UIKit                               0x007d6eeb UIApplicationMain + 1225
    26  Road Safety App V2                  0x00002f9d main + 141
    27  libdyld.dylib                       0x0308470d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)  

and Ideas as to why i am having this problem? and a solution would also be appreciated.

도움이 되었습니까?

해결책

This line switch (self.driverKnown.selectedSegmentIndex) { is accessing a property named driverKnown but that driver is unknown. The stack trace and exception are telling you that driverKnown is an undeclared or unknock getter method for the property.

The exception calls out DobInAHoonViewController which in that line of code would be the self. Is driverKnown suppose to be the name of your UISegmentedControl? Can we see the creation of said UISegmentedControl?

다른 팁

your method doesn't know selectedSegmentIndex . because you not value of segment value changed

UISegmentControl *mySegmentedControl = [[UISegmentControl alloc]init];
    [mySegmentedControl addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];


- (IBAction)segmentValueChanged:(id)sender {
    UISegmentedControl *driverKnown = (UISegmentedControl *)sender;

  switch (driverKnown.selectedSegmentIndex) {
        case 0:
            driverKnownResponse = @"Yes";
            break;

        case 1:
            driverKnownResponse = @"No";
            break;
        default:
            break;
    }


}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top