Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 918941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:27:37+00:00 2026-05-15T18:27:37+00:00

This is my first app. It doesn’t crash the simulator just brings you back

  • 0

This is my first app. It doesn’t crash the simulator just brings you back to the home screen. This isn’t my first cocoa program (I’m not a pro at cocoa either)just my first iPhone.

It crashes when you press the letsPlayButton, which runs the -(IBAction)letsPlay:(id)sender; method.

Help me! Im so lost with what’s wrong!

.H

#import <UIKit/UIKit.h>

@interface BrainiacViewController : UIViewController {
    IBOutlet    UILabel     *theQuestion;
    IBOutlet    UILabel     *theScore;
    IBOutlet    UILabel     *theLives;
    IBOutlet    UIButton    *answerOne;
    IBOutlet    UIButton    *answerTwo;
    IBOutlet    UIButton    *answerThree;
    IBOutlet    UIButton    *answerFour;
    IBOutlet    UIButton    *letsPlayButton;
    NSString  *questionNumber;
    NSInteger myScore;
    NSInteger myLives;
    NSInteger usersAnswer;
    NSArray   *theQuiz;

    //quiz dictionarys
    NSMutableDictionary *question, *rightAnswer, *wrongOne, *wrongTwo, *wrongThree;
}

-(IBAction)buttonOne:(id)sender;
-(IBAction)buttonTwo:(id)sender;
-(IBAction)buttonThree:(id)sender;
-(IBAction)buttonFour:(id)sender;
-(IBAction)letsPlay:(id)sender;

-(void)checkAnswer;

-(void)askQuestion;

-(void)updateScore;

-(void)loadQuiz;
@end

.M

#import "BrainiacViewController.h"

@implementation BrainiacViewController

-(void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
- (void)dealloc {
    [super dealloc];
}

-(IBAction)buttonOne:(id)sender{
    usersAnswer = 1;
}
-(IBAction)buttonTwo:(id)sender{
    usersAnswer = 2;
}
-(IBAction)buttonThree:(id)sender{
    usersAnswer = 3;
}
-(IBAction)buttonFour:(id)sender{
    usersAnswer = 4;
}
-(IBAction)letsPlay:(id)sender{
    //un hide answer buttons
    [answerOne setHidden:NO];
    [answerTwo setHidden:NO];
    [answerThree setHidden:NO];
    [answerFour setHidden:NO];

    //hide the lets play button
    [letsPlayButton setHidden:YES]; 

    //assign values to variables
    myScore = 0;
    myLives = 3;
    questionNumber = 0; 
    //ask question and start game
    [self askQuestion];
}


-(void)checkAnswer{
    [question objectForKey:questionNumber];
    [rightAnswer objectForKey:questionNumber];
    [wrongOne objectForKey:questionNumber];
    [wrongTwo objectForKey:questionNumber];
    [wrongThree objectForKey:questionNumber];

}

-(void)askQuestion{
    //create array to mix up the possible answers
    NSMutableArray *possibleAnswers = [[NSMutableArray alloc] init];
    [possibleAnswers addObject:[rightAnswer objectForKey:questionNumber] ];
    [possibleAnswers addObject:[wrongOne objectForKey:questionNumber] ];
    [possibleAnswers addObject:[wrongTwo objectForKey:questionNumber] ];
    [possibleAnswers addObject:[wrongThree objectForKey:questionNumber] ];


    //set labels/buttons for question
    theQuestion.text = [question objectForKey:questionNumber];


    //user picks a answer button and sets a value to usersAnswer
    questionNumber = questionNumber + 1;
    [self checkAnswer];

}

-(void)updateScore{
}

-(void)loadQuiz{ //assigns dictionary values
    //*KEY* defines question number
    [question    setObject:@"Which is NOT a starwars movie?" forKey:@"1"];
    [rightAnswer setObject:@"Attack of the Jedi" forKey:@"1"];
    [wrongOne    setObject:@"A New Hope" forKey:@"1"];
    [wrongTwo    setObject:@"The Phantom Menace" forKey:@"1"];
    [wrongThree  setObject:@"Attack of the Clones" forKey:@"1"];

    [question    setObject:@"In what state is the majority of Yellow Stone National Park in?" forKey:@"2"];
    [rightAnswer setObject:@"Wyoming" forKey:@"2"];
    [wrongOne    setObject:@"California" forKey:@"2"];
    [wrongTwo    setObject:@"Ohio" forKey:@"2"];
    [wrongThree  setObject:@"Nebraska" forKey:@"2"];

    [question    setObject:@"In the US, what household pet is the most common?" forKey:@"2"];
    [rightAnswer setObject:@"Dogs" forKey:@"2"];
    [wrongOne    setObject:@"Cats" forKey:@"2"];
    [wrongTwo    setObject:@"Hamsters" forKey:@"2"];
    [wrongThree  setObject:@"Komodo Dragons" forKey:@"2"];

    [question    setObject:@"A plane is traveling 2675 miles every 5 hours. How fast is the plane going in Miles per Hour?" forKey:@"3"];
    [rightAnswer setObject:@"535 Mph" forKey:@"3"];
    [wrongOne    setObject:@"325 Mph" forKey:@"3"];
    [wrongTwo    setObject:@"535 Mph" forKey:@"3"];
    [wrongThree  setObject:@"420 Mph" forKey:@"3"];
}
@end

appdelagate.h

#import <UIKit/UIKit.h>

@class BrainiacViewController;

@interface BrainiacAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    BrainiacViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet BrainiacViewController *viewController;

@end

appdelegate.m

#import "BrainiacAppDelegate.h"
#import "BrainiacViewController.h"

@implementation BrainiacAppDelegate

@synthesize window;
@synthesize viewController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}


- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}

- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}


@end

I tried it again and checked the console and the error was this..I dont know what that means.

[Session started at 2010-07-11 12:24:40 -0400.]
2010-07-11 12:24:45.729 Brainiac[46764:207] -[NSCFString letsPlay:]: unrecognized selector sent to instance 0x5944f00
2010-07-11 12:24:45.733 Brainiac[46764:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString letsPlay:]: unrecognized selector sent to instance 0x5944f00'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x02395919 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x024e35de objc_exception_throw + 47
    2   CoreFoundation                      0x0239742b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x02307116 ___forwarding___ + 966
    4   CoreFoundation                      0x02306cd2 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x002b9e14 -[UIApplication sendAction:to:from:forEvent:] + 119
    6   UIKit                               0x003436c8 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x00345b4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    8   UIKit                               0x003446f7 -[UIControl touchesEnded:withEvent:] + 458
    9   UIKit                               0x002dd2ff -[UIWindow _sendTouchesForEvent:] + 567
    10  UIKit                               0x002bf1ec -[UIApplication sendEvent:] + 447
    11  UIKit                               0x002c3ac4 _UIApplicationHandleEvent + 7495
    12  GraphicsServices                    0x02bfbafa PurpleEventCallback + 1578
    13  CoreFoundation                      0x02376dc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    14  CoreFoundation                      0x022d7737 __CFRunLoopDoSource1 + 215
    15  CoreFoundation                      0x022d49c3 __CFRunLoopRun + 979
    16  CoreFoundation                      0x022d4280 CFRunLoopRunSpecific + 208
    17  CoreFoundation                      0x022d41a1 CFRunLoopRunInMode + 97
    18  GraphicsServices                    0x02bfa2c8 GSEventRunModal + 217
    19  GraphicsServices                    0x02bfa38d GSEventRun + 115
    20  UIKit                               0x002c7b58 UIApplicationMain + 1160
    21  Brainiac                            0x00002790 main + 102
    22  Brainiac                            0x00002721 start + 53
)
terminate called after throwing an instance of 'NSException'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:27:37+00:00Added an answer on May 15, 2026 at 6:27 pm

    I tried it again and checked the console and the error was this..I dont know what that means.

    2010-07-11 12:24:45.729 Brainiac[46764:207] -[NSCFString letsPlay:]: unrecognized selector sent to instance 0x5944f00
    

    You sent a message (letsPlay:) to an object that does not respond to that message (an NSString, shown here as NSCFString).

    This sort of thing usually happens because you didn’t properly hold on to the object that you meant to send letsPlay: to, so it got deallocated. An NSString later got allocated at the same address, so everything that had been holding the pointer to the old object (and thinks it still is) is now holding the pointer to the NSString. Same pointer, different object. Then, when one of those would-be owners tries to send the message to the object it thinks it still has… boom.

    The fix is to check your ownerships and make sure you’re retaining (or creating using alloc and not autoreleasing) what you mean to own.

    On a related note:

    NSMutableArray *possibleAnswers = [[NSMutableArray alloc] init];
    [possibleAnswers addObject:[rightAnswer objectForKey:questionNumber] ];
    [possibleAnswers addObject:[wrongOne objectForKey:questionNumber] ];
    [possibleAnswers addObject:[wrongTwo objectForKey:questionNumber] ];
    [possibleAnswers addObject:[wrongThree objectForKey:questionNumber] ];
    

    If you mean for this to be a local variable, you must release it by the end of the method, or you will leak this array.

    If you mean to own this object, you should move it to an instance variable, and drop the local variable, and continue creating the object as you are doing now.

    Required reading: The Memory Management Programming Guide for Cocoa.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.