线程1:主要信号SIGABRT错误

时间:2013-11-20 04:08:36

标签: ios xcode debugging

在main函数中收到此错误消息。我是Xcode 5中调试此类错误的新手,所以非常感谢您就如何处理此类错误提出建议。

提前致谢。

以下是代码:

主:

#import <UIKit/UIKit.h>

#import "BullsEyeAppDelegate.h"

int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([BullsEyeAppDelegate class])); //Thread 1: signal SIGABRT
    }
}

BullsEyeViewController.h

#import <UIKit/UIKit.h>

@interface BullsEyeViewController : UIViewController

@property (nonatomic, weak) IBOutlet UISlider *slider;
@property (nonatomic, weak) IBOutlet UILabel *targetLabel;
@property (nonatomic, weak) IBOutlet UILabel *scoreLabel;
@property (nonatomic, weak) IBOutlet UILabel *roundLabel;

-(IBAction)showAlert;
-(IBAction)sliderMoved:(UISlider *)slider;



@end

BullsEyeViewController.m

#import "BullsEyeViewController.h"

@interface BullsEyeViewController ()

@end

@implementation BullsEyeViewController
{
    int _currentValue;
    int _targetValue;
    int _score;
    int _round;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self startNewRound];
    [self updateLabels];
}

-(void)startNewRound
{
    _targetValue = 1 + arc4random_uniform(100);
    _currentValue = 50;
    self.slider.value = _currentValue;
    [self updateLabels];
}

-(void)updateLabels
{
    self.targetLabel.text = [NSString stringWithFormat:@"%d", _targetValue];
    // Convert the int into a string so that it will fit in the label as an outlet
    self.scoreLabel.text = [NSString stringWithFormat:@"%d", _score];
    self.roundLabel.text = [NSString stringWithFormat:@"%d", _round];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)showAlert
{
    int difference = abs(_currentValue - _targetValue);
    int points = 100 - difference;
    _score += points;

    NSString *message = [NSString stringWithFormat:@"You scored %d points", points];

    UIAlertView *alertView = [[UIAlertView alloc]
    initWithTitle:@"Hello World"
          message:message
         delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];

    [alertView show];

    [self startNewRound];
    [self updateLabels];
}

-(IBAction)sliderMoved:(UISlider *)slider
{
    _currentValue = lroundf(slider.value);
}

@end

错误追踪:

2013-11-19 19:59:12.299 BullsEye[13764:70b] -[UILabel intValue]: unrecognized selector sent to instance 0x8a7ef20
2013-11-19 19:59:12.351 BullsEye[13764:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel intValue]: unrecognized selector sent to instance 0x8a7ef20'
*** First throw call stack:
(
    0   CoreFoundation                      0x0173a5e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x014bd8b6 objc_exception_throw + 44
    2   CoreFoundation                      0x017d7903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0172a90b ___forwarding___ + 1019
    4   CoreFoundation                      0x0172a4ee _CF_forwarding_prep_0 + 14
    5   Foundation                          0x0117d737 _NSSetIntValueForKeyInIvar + 46
    6   Foundation                          0x010eada3 _NSSetUsingKeyValueSetter + 256
    7   Foundation                          0x010ea253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
    8   Foundation                          0x0114c70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
    9   UIKit                               0x004cda15 -[UIRuntimeOutletConnection connect] + 106
    10  libobjc.A.dylib                     0x014cf7d2 -[NSObject performSelector:] + 62
    11  CoreFoundation                      0x01735b6a -[NSArray makeObjectsPerformSelector:] + 314
    12  UIKit                               0x004cc56e -[UINib instantiateWithOwner:options:] + 1417
    13  UIKit                               0x0033e605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
    14  UIKit                               0x0033edad -[UIViewController loadView] + 302
    15  UIKit                               0x0033f0ae -[UIViewController loadViewIfRequired] + 78
    16  UIKit                               0x0033f5b4 -[UIViewController view] + 35
    17  UIKit                               0x002679fd -[UIWindow addRootViewControllerViewIfPossible] + 66
    18  UIKit                               0x00267d97 -[UIWindow _setHidden:forced:] + 312
    19  UIKit                               0x0026802d -[UIWindow _orderFrontWithoutMakingKey] + 49
    20  UIKit                               0x0027289a -[UIWindow makeKeyAndVisible] + 65
    21  UIKit                               0x00225cd0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
    22  UIKit                               0x0022a3a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
    23  UIKit                               0x0023e87c -[UIApplication handleEvent:withNewEvent:] + 3447
    24  UIKit                               0x0023ede9 -[UIApplication sendEvent:] + 85
    25  UIKit                               0x0022c025 _UIApplicationHandleEvent + 736
    26  GraphicsServices                    0x036e12f6 _PurpleEventCallback + 776
    27  GraphicsServices                    0x036e0e01 PurpleEventCallback + 46
    28  CoreFoundation                      0x016b5d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
    29  CoreFoundation                      0x016b5a9b __CFRunLoopDoSource1 + 523
    30  CoreFoundation                      0x016e077c __CFRunLoopRun + 2156
    31  CoreFoundation                      0x016dfac3 CFRunLoopRunSpecific + 467
    32  CoreFoundation                      0x016df8db CFRunLoopRunInMode + 123
    33  UIKit                               0x00229add -[UIApplication _run] + 840
    34  UIKit                               0x0022bd3b UIApplicationMain + 1225
    35  BullsEye                            0x0000219d main + 141
    36  libdyld.dylib                       0x01d7870d start + 1
    37  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

1 个答案:

答案 0 :(得分:0)

这两行显示错误跟踪中的错误:

2013-11-19 19:59:12.299 BullsEye[13764:70b] -[UILabel intValue]: unrecognized selector sent to instance 0x8a7ef20
2013-11-19 19:59:12.351 BullsEye[13764:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel intValue]: unrecognized selector sent to instance 0x8a7ef20'

看来您的错误不是由您发布的代码引起的,而是您所拥有的代码:

[UILabel intValue];

无论您使用上面的代码,在尝试获取{{1}的UILabel属性的整数值时,都会尝试获取text的整数值。 }}。

因此,假设您的标签名称为“myLabel:”

UILabel