SIGABRT Xcode ???需要帮助

时间:2012-12-02 19:58:13

标签: ios iphone xcode sigabrt

我目前是新开发者,我遇到了这个错误; SIGABRT。我尝试过开发很多应用程序,其中很多都会出现这个错误。我正在为小孩子开发一个声音匹配的教育应用程序,他们在Xcode中使用一个选择器视图来匹配动物和他们的声音。我的代码如下:

ViewController.m

#define componentCount 2
#define animalComponent 0
#define soundComponent 1
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize lastAction;
@synthesize matchResult;

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    NSString *actionMessage;
    NSString *matchMessage;
    int selectedAnimal;
    int selectedSound;
    int matchedSound;

    if (component==animalComponent) {
        actionMessage=[[NSString alloc]
                       initWithFormat:@"You Selected The Animal Named '%@'!",
                       [animalNames objectAtIndex:row]];

    } else {
        actionMessage=[[NSString alloc]
                       initWithFormat:@"You Selected The Animal Sound '%@'!",
                       [animalSounds objectAtIndex:row]];
    }

    selectedAnimal=[pickerView selectedRowInComponent:animalComponent];
    selectedSound=[pickerView selectedRowInComponent:soundComponent];

    matchedSound=([animalSounds count] - 1) -
    [pickerView selectedRowInComponent:soundComponent];

    if (selectedAnimal==matchedSound) {
        matchMessage=[[NSString alloc] initWithFormat:@"Yes, A '%@' Does Go '%@'!"];
        [animalNames objectAtIndex:selectedAnimal],
        [animalSounds objectAtIndex:selectedSound];
    } else {
        matchMessage=[[NSString alloc] initWithFormat:@"No, A '%@' Doesn't Go '%@'!"];
        [animalNames objectAtIndex:selectedAnimal],
        [animalSounds objectAtIndex:selectedSound];
    }

    lastAction.text=actionMessage;
    matchResult.text=matchMessage;

    [matchMessage release];
    [actionMessage release];
}



- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    if (component==animalComponent) {
        return [animalNames objectAtIndex:row];
    } else {
        return [animalSounds objectAtIndex:row];
    }
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    if (component==animalComponent) {
        return [animalNames count];
    } else {
        return [animalSounds count];
    }
}

- (void)dealloc {
    [animalNames release];
    [animalSounds release];
    [lastAction release];
    [matchResult release];
    [super dealloc];
}

- (void)viewDidLoad {
    animalNames=[[NSArray alloc]initWithObjects:
                 @"Cat", @"Dog", @"Snake", @"Cow", @"Horse", @"Pig", @"Duck", @"Sheep", @"Bird",nil];
    animalSounds=[[NSArray alloc]initWithObjects:
                 @"Chirp", @"Baa", @"Quack", @"Oink", @"Nay", @"Moo", @"Hiss", @"Bark", @"Purr",nil];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate> {
    NSArray *animalNames;
    NSArray *animalSounds;
    IBOutlet UILabel *lastAction;
    IBOutlet UILabel *matchResult;
}

@property (nonatomic, retain) UILabel *lastAction;
@property (nonatomic, retain) UILabel *matchResult;

@end

SIGABRT在哪里

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        //at end of row of code above this, there was the error message: signal SIGABRT
    }
}

无论如何,我绝对需要帮助我应该做什么才能摆脱这个SIGABRT错误。谢谢。

3 个答案:

答案 0 :(得分:3)

您必须确定导致问题的代码行,这是我们无法从代码片段中识别的内容。

您可能希望启用异常断点,因为它们通常可以识别导致异常的精确确切代码行。当我在开发中遇到异常时,我只会在“所有”异常上添加异常断点(请参阅下面的Breakpoint Navigator Help或屏幕快照)。这样,如果我通过我的调试器运行程序,当它遇到异常时,它将停止违规行的代码,大大简化了识别问题根源的过程。它并不总是完美地工作,但它经常比其他技术更快地找到异常的来源。

all exceptions

有关调试应用程序的更广泛讨论(例如,使用调试器单步执行代码,请参阅Xcode User Guide: Debug your App。如果您知道此方法存在问题,则可能需要step through your code,逐行,问题将变得不言而喻。


我还建议您查看Ray Wenderlich网站上的My App Crashed, Now What

答案 1 :(得分:0)

您的匹配消息似乎存在一些格式问题:

matchMessage=[[NSString alloc] initWithFormat:@"Yes, A '%@' Does Go '%@'!"];
[animalNames objectAtIndex:selectedAnimal],
[animalSounds objectAtIndex:selectedSound];

我很惊讶编译器实际上会编译它,但无论如何 - 你需要在方法调用中包含所选的字符串stringWithFormat:

尝试以下:

matchMessage = [[NSString alloc] initWithFormat:@"Yes, A '%@' Does Go '%@'!", 
    [animalNames objectAtIndex:selectedAnimal],
    [animalSounds objectAtIndex:selectedSound]
];

您的编译器肯定会给您一个警告。所以你的第一步应该始终是修复编译器警告。在构建设置中打开“将警告视为错误”选项是一种很好的做法。这意味着编译器对接受和运行的内容非常严格 - 这意味着您必须修复警告。没有理由从你的编译器发出警告。

答案 2 :(得分:0)

在第一个调用堆栈之前阅读英文。它告诉你什么?最常见的sigabrt形式是在.h文件中删除git tag并且故事板中的插座连接仍然存在。要解决此问题,请删除故事板中的所有插座连接,重写IBOutlet,然后重新链接它们。