私は現在、新しい開発者ですが、このエラーに遭遇しました。SIGABRT。多くのアプリを開発しようとしましたが、多くのアプリでこのエラーが発生します。私は、Xcode で 1 つのピッカー ビューを使用して動物とその音を一致させる、小さな子供向けのサウンド マッチング教育アプリを開発しています。私のコードは次のとおりです。
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 エラーを取り除くために何をすべきかについて、絶対に助けが必要です。ありがとうございました。