我目前是一名新開發人員,遇到此錯誤; SIGABRT。我曾嘗試開發許多應用程序,並且他們中的很多人都會遇到此錯誤。我正在開發一個適合小孩的聲音匹配教育應用,他們在Xcode中使用一個選擇器視圖來匹配動物和他們的聲音。我的代碼如下: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錯誤,我絕對需要幫助。謝謝。
SIGABRT通常會在運行控制檯中顯示一條消息,它會以相當通俗的英文顯示錯誤。如果錯誤不是不言自明的,請將其作爲對問題的修改。 – Greg
IBOutlets設置是否正確? –
來自'main'的標記行並沒有幫助,因爲這沒有告訴我們什麼。此外,幾乎總是有一個相對容易理解的錯誤信息。用這些信息解決這個問題要快得多。我知道我不打算梳理沒有任何信息的代碼頁。 – Metabble