SIGABRT错误 - 分段控制

时间:2014-01-30 02:34:56

标签: ios objective-c sigabrt

我有一个分段控件,根据选择的内容,它是为NS字符串分配一个值,如下所示:

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

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

然而,它在下一行抛出一个SIGABRT:

#import "RoadSafetyAppAppDelegate.h"

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

这是控制台输出:

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)  

和想法为什么我有这个问题?并且也将不胜感激。

2 个答案:

答案 0 :(得分:2)

此行switch (self.driverKnown.selectedSegmentIndex) {正在访问名为driverKnown的属性,但该驱动程序未知。堆栈跟踪和异常告诉您driverKnown是该属性的未声明或unknock getter方法。

异常调出DobInAHoonViewController,该代码行中的driverKnown将是self。 UISegmentedControlUISegmentedControl的名称吗?我们可以看到{{1}}的创建吗?

答案 1 :(得分:0)

您的方法不知道selectedSegmentIndex。因为您没有更改分段值的值

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;
    }


}