我一直在研究iPhone应用程序Cruzia,并且想知道为什么每当我点击我游戏的选项菜单中的一个开关时,我在模拟器中出现这个SIGABRT错误的原因。这是我的15个主文件,错误已注释掉。
#import <UIKit/UIKit.h>
#import "CIAAppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([CIAAppDelegate class]));
//Thread 1: signal SIGABRT
}
}
供参考,这是我的ViewController.m
#import "CIAViewController.h"
@interface CIAViewController()
@end
@implementation CIAViewController
-(IBAction)press {
cruzia.hidden = 0;
textarea.hidden = 0;
playbtn.hidden = 1;
tutorialbtn.hidden = 1;
optionsbtn.hidden = 1;
trainingbtn.hidden = 1;
back.hidden = 0;
soundlbl.hidden = 1;
music.hidden = 1;
sound.hidden = 1;
musiclbl.hidden = 1;
cruzia.text = @"Play";
textarea.text = @"Hello! You are playing the game of Cruzia!";
if (clicked == 1) {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click", CFSTR ("electronic click.wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
}
-(IBAction)press2 {
cruzia.hidden = 0;
textarea.hidden = 0;
playbtn.hidden = 1;
tutorialbtn.hidden = 1;
optionsbtn.hidden = 1;
trainingbtn.hidden = 1;
back.hidden = 0;
soundlbl.hidden = 1;
music.hidden = 1;
sound.hidden = 1;
musiclbl.hidden = 1;
cruzia.text = @"Tutorial";
textarea.text = @"Welcome! You are watching the Cruzia tutorial!";
if (clicked == 1) {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click", CFSTR ("electronic click.wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
}
-(IBAction)press3 {
cruzia.hidden = 0;
textarea.hidden = 0;
playbtn.hidden = 1;
tutorialbtn.hidden = 1;
optionsbtn.hidden = 1;
trainingbtn.hidden = 1;
back.hidden = 0;
soundlbl.hidden = 0;
music.hidden = 0;
sound.hidden = 0;
musiclbl.hidden = 0;
cruzia.text = @"Options";
textarea.text = @"Hello! You have clicked Options. To control other areas of the gane, go to the settings app and open the Cruzia addon.";
if (clicked == 1) {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click", CFSTR ("electronic click.wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
}
-(IBAction)press4 {
cruzia.hidden = 0;
textarea.hidden = 0;
playbtn.hidden = 1;
tutorialbtn.hidden = 1;
optionsbtn.hidden = 1;
trainingbtn.hidden = 1;
back.hidden = 0;
soundlbl.hidden = 1;
music.hidden = 1;
sound.hidden = 1;
musiclbl.hidden = 1;
cruzia.text = @"Training";
textarea.text = @"This is the training area. You can improve your Cruzia skills here!";
if (clicked == 1) {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click", CFSTR ("electronic click.wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
}
-(IBAction)returnpress
{
cruzia.hidden = 0;
textarea.hidden = 0;
playbtn.hidden = 0;
tutorialbtn.hidden = 0;
optionsbtn.hidden = 0;
trainingbtn.hidden = 0;
back.hidden = 1;
soundlbl.hidden = 1;
music.hidden = 1;
sound.hidden = 1;
musiclbl.hidden = 1;
cruzia.text = @"Cruzia";
textarea.text = @"";
if (clicked == 1) {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click", CFSTR ("electronic click.wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
}
- (void)viewDidLoad
{
textarea.hidden = 1;
playbtn.hidden = 0;
tutorialbtn.hidden = 0;
optionsbtn.hidden = 0;
trainingbtn.hidden = 0;
back.hidden = 1;
soundlbl.hidden = 1;
music.hidden = 1;
sound.hidden = 1;
musiclbl.hidden = 1;
cruzia.text = @"Cruzia";
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateSettings:)
name:
NSUserDefaultsDidChangeNotification object:nil];
[self setupDefaults];
}
- (void)viewDidUnload
{
[super viewDidUnload];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidFinishLaunchingNotification object:nil];
}
-(void) setupDefaults {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *violenceValue = [defaults stringForKey:kViolenceMode];
if ( violenceValue == nil ) {
NSString *pathStr = [[NSBundle mainBundle] bundlePath];
NSString *settingsBundlePath = [pathStr stringByAppendingPathComponent:@"Settings.bundle"];
NSString *finalPath = [settingsBundlePath stringByAppendingPathComponent:@"Root.plist"];
NSDictionary *settingsDictionary = [NSDictionary dictionaryWithContentsOfFile:finalPath];
NSArray *prefSpecifierArray = [settingsDictionary objectForKey:@"PreferenceSpecifiers"];
NSString *violence_identifier, *isPushNotifyOn;
NSDictionary *prefItem;
for (prefItem in prefSpecifierArray) {
NSString *keyValue = [prefItem objectForKey:@"Key"];
id defaultValue = [prefItem objectForKey:@"DeafultValue"];
if ([keyValue isEqualToString:kViolenceMode])
{
violence_identifier = defaultValue;
}
else if ([keyValue isEqualToString:kPushNotifications])
{
isPushNotifyOn = defaultValue;
}
NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys: violence_identifier, kViolenceMode, isPushNotifyOn, kPushNotifications, nil];
[defaults registerDefaults:appDefaults];
[defaults synchronize];
}
}
}
@end
这是我的.h:
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
int clicked;
#define kViolenceMode @"violence_identifier"
#define kPushNotifications @"isPushNotifyOn"
@interface CIAViewController : UIViewController {
IBOutlet UILabel *cruzia;
IBOutlet UILabel *textarea;
IBOutlet UIButton *playbtn;
IBOutlet UIButton *tutorialbtn;
IBOutlet UIButton *optionsbtn;
IBOutlet UIButton *trainingbtn;
IBOutlet UIButton *back;
IBOutlet UISwitch *music;
IBOutlet UISwitch *sound;
IBOutlet UILabel *soundlbl;
IBOutlet UILabel *musiclbl;
}
- (void) setupDefaults;
-(IBAction)press;
-(IBAction)press2;
-(IBAction)press3;
-(IBAction)press4;
-(IBAction)returnpress;
-(IBAction)music;
-(IBAction)sound;
@end
如果有人知道我为什么会收到这个错误,如果能告诉我,我会非常感激。 -George