ios - SIGABRT Xcode???需要帮助

标签 ios iphone xcode sigabrt

我目前是一名新开发人员,遇到了这个错误; SIGABRT。我尝试过开发许多应用程序,其中很多都收到此错误。我正在为 child 子开发一个声音匹配教育应用程序,他们使用 Xcode 中的一个选择器 View 来匹配动物及其声音。我的代码如下:

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 错误,我绝对需要帮助。谢谢你。

最佳答案

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

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

all exceptions

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

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

关于ios - SIGABRT Xcode???需要帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13673222/

相关文章:

ios - "memory history"命令到底是什么?

ios - 在 UITableViewDelegate 方法 heightForRowAtIndexPath 中获取 TableView 单元格属性 :

android - 在 iOS 和 Android 上使用 Google Play 游戏服务的 Libgdx 游戏

ios - FileManager 无法在 Xcode 项目中找到 PDF 目录

iphone - 获取TMXTiledMap的tileet文件名

ios - iOS 8 上的 UIWebView 崩溃

iphone - iPhone 应用程序的保持登录选项

iphone - 深度链接 iOS 推送通知

iphone - 从远程数据库中检索数据

ios - 发现意外的 Mach-O header 代码 : 0x72613c21 on submitting to App Store