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 6975133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:19:45+00:00 2026-05-27T17:19:45+00:00

i am developing very simple quiz app In viewDidLoad i am adding objects in

  • 0

i am developing very simple quiz app

In viewDidLoad i am adding objects in myarray

where ever i nslog myarray values it works fine

but if i try this inside ibaction methods all objects becomes zombie

for 2 days i am stuck in this but can’t find it what is wrong.

quiz.h

#import <UIKit/UIKit.h>
#import <sqlite3.h>

@class dbVals;
@class viewTransition;
@class AppDelegate;

@interface quiz : UIViewController
{
    NSMutableArray *myarray;

    IBOutlet UITextView *questionTextView_;

    IBOutlet UIButton *skipButton_;

    IBOutlet UIButton *optionAButton_;

    IBOutlet UIButton *optionBButton_;

    IBOutlet UIButton *optionCButton_;

    NSString *correctAnswer;

    int questionNumber;

    int score;

    IBOutlet UILabel *scoreLabel_;

    int totalQuestions;

}

-(void)populate:(int)number;

//@property(nonatomic, retain) NSMutableArray *myarray;

@property (retain, nonatomic) IBOutlet UITextView *questionTextView;

@property (retain, nonatomic) IBOutlet UIButton *skipButton;

@property (retain, nonatomic) IBOutlet UIButton *optionAButton;

@property (retain, nonatomic) IBOutlet UIButton *optionBButton;

@property (retain, nonatomic) IBOutlet UIButton *optionCButton;

@property (retain, nonatomic) IBOutlet UILabel *scoreLabel;

- (IBAction)optionsToAnswer:(id)sender;

- (IBAction)zzz:(id)sender;

@end

quiz.m

#import "quiz.h"
#import "DbVals.h"
#import "viewTransition.h"
#import "AppDelegate.h"

@implementation quiz
@synthesize skipButton=skipButton_;
@synthesize optionAButton=optionAButton_;
@synthesize optionBButton=optionBButton_;
@synthesize optionCButton=optionCButton_;
@synthesize scoreLabel=scoreLabel_;
@synthesize questionTextView=questionTextView_;

//@synthesize myarray;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (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.
}

#pragma mark - View lifecycle

- (void)createEditableCopyOfDatabaseIfNeeded
{
    //NSLog(@"Creating editable copy of database");
    // First, test for existence.
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"oq.sqlite"];
    success = [fileManager fileExistsAtPath:writableDBPath];
    if (success) return;
    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"oq.sqlite"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
    if (!success) {
        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}

+(sqlite3 *) getNewDBConnection
{
    sqlite3 *newDBconnection;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"oq.sqlite"];
    // Open the database. The database was prepared outside the application.
    if (sqlite3_open([path UTF8String], &newDBconnection) == SQLITE_OK) {

        //NSLog(@"Database Successfully Opened  ");

    } else {
        NSLog(@"Error in opening database  ");
    }

    return newDBconnection; 
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    questionNumber = 0;

    score = 0;

    [self createEditableCopyOfDatabaseIfNeeded];    

    sqlite3 *dbc = [quiz getNewDBConnection];

    sqlite3_stmt *statement = nil;

    const char *sqlSelect = "select * from QnA ORDER BY RANDOM()";

    if(sqlite3_prepare_v2(dbc, sqlSelect, -1, &statement, NULL)!=SQLITE_OK)
    {
        NSAssert1(0, @"Error Preparing Statement", sqlite3_errmsg(dbc));
    }
    else
    {
        myarray = [[NSMutableArray alloc]init];

        while(sqlite3_step(statement)==SQLITE_ROW)
        {
            NSString *q = [NSString stringWithUTF8String:(char *) sqlite3_column_text(statement, 0)];
            NSString *o = [NSString stringWithUTF8String:(char *) sqlite3_column_text(statement, 1)];
            NSString *a = [NSString stringWithUTF8String:(char *) sqlite3_column_text(statement, 2)];

            DbVals *dbValsObj = [[DbVals alloc]init];            
            [dbValsObj setValsOfQuestions:q options:o answer:a];                
            [myarray addObject:dbValsObj];            
            [dbValsObj release];          
        }
    }

    sqlite3_finalize(statement);

    //[self populate:questionNumber];

}

-(void)populate:(int)number
{
    /*[scoreLabel_ setText:[NSString stringWithFormat:@"%d",score]];

    AppDelegate *appDel = [[UIApplication sharedApplication] delegate];
    [appDel setFinalScore:[NSString stringWithFormat:@"%d",score]];

    if(number < [myarray count])
    {
        DbVals *dbv1 = [myarray objectAtIndex:number];

        [questionTextView_ setText:[dbv1 getQuestions]];

        NSString *joinedOptions = [dbv1 getOptions];

        NSArray *splitOptions = [joinedOptions componentsSeparatedByString:@","];
        [optionAButton_ setTitle:[splitOptions objectAtIndex:0] forState:UIControlStateNormal];
        [optionBButton_ setTitle:[splitOptions objectAtIndex:1] forState:UIControlStateNormal];
        [optionCButton_ setTitle:[splitOptions objectAtIndex:2] forState:UIControlStateNormal];

        correctAnswer = [dbv1 getAnswer];
    }
    else
    {
        //viewTransition *vt = [[viewTransition alloc]init];
        [viewTransition viewsTransitionCurrentView:self toNextView:@"result"];
        //[vt release];       
    }*/
}

- (void)viewDidUnload
{
    for(int i=0; i<[myarray count]; i++)
    {
        DbVals *dbv1 = [myarray objectAtIndex:i];
        NSLog(@"%@",[dbv1 getQuestions]);
        NSLog(@"%@",[dbv1 getOptions]);
        NSLog(@"%@",[dbv1 getAnswer]);
        NSLog(@"<u><u><u><u><><><><><><><><><><><>");
    }

    [self setQuestionTextView:nil];
    [questionTextView_ release];
    questionTextView_ = nil;
    [self setQuestionTextView:nil];
    [skipButton_ release];
    skipButton_ = nil;
    [self setSkipButton:nil];
    [optionAButton_ release];
    optionAButton_ = nil;
    [self setOptionAButton:nil];
    [optionBButton_ release];
    optionBButton_ = nil;
    [self setOptionBButton:nil];
    [optionCButton_ release];
    optionCButton_ = nil;
    [self setOptionCButton:nil];
    [scoreLabel_ release];
    scoreLabel_ = nil;
    [self setScoreLabel:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc
{
    for(int i=0; i<[myarray count]; i++)
    {
        DbVals *dbv1 = [myarray objectAtIndex:i];
        NSLog(@"%@",[dbv1 getQuestions]);
        NSLog(@"%@",[dbv1 getOptions]);
        NSLog(@"%@",[dbv1 getAnswer]);
        NSLog(@"<d><d><d><d><d><><><><><><><><><><>");
    }

    [questionTextView_ release];

    [skipButton_ release];

    [optionAButton_ release];

    [optionBButton_ release];

    [optionCButton_ release];

    [scoreLabel_ release];

    [myarray release];

    [super dealloc];
}

- (IBAction)optionsToAnswer:(id)sender
{
    for(int i=0; i<[myarray count]; i++)
    {
        DbVals *dbv1 = [myarray objectAtIndex:i];
        NSLog(@"%@",[dbv1 getQuestions]);
        NSLog(@"%@",[dbv1 getOptions]);
        NSLog(@"%@",[dbv1 getAnswer]);
        NSLog(@"six");
    }


    if(sender == skipButton_)
    {
        //questionNumber++;

        //[self populate:questionNumber];

        /*[UIView animateWithDuration:5 delay:0 options: UIViewAnimationCurveEaseOut
        animations:
        ^{
            [UIView setAnimationTransition:103 forView:self.view cache:NO]; 
        } 
        completion:
        ^(BOOL finished)
        {                             
        }
        ];*/
    }

    if(sender == optionAButton_)
    {
        /*NSString *one = @"1";
        if([correctAnswer isEqualToString:one])
        {
            score++;
        }
        questionNumber++;
        [self populate:questionNumber];*/
    }

    if(sender == optionBButton_)
    {
        /*NSString *two = @"2";
        if([correctAnswer isEqualToString:two])
        {
            score++;
        }
        questionNumber++;
        [self populate:questionNumber];*/
    }

    if(sender == optionCButton_)
    {
        /*NSString *three = @"3";
        if([correctAnswer isEqualToString:three])
        {
            score++;
        }
        questionNumber++;
        [self populate:questionNumber];*/
    }
}

- (IBAction)zzz:(id)sender 
{
}
@end

dbVals.h

#import <Foundation/Foundation.h>

@interface DbVals : NSObject
{
    NSString *questions_;
    NSString *options_;
    NSString *answer_;
    //    NSString *hint;
    //    NSString *mode;
}

-(void)setValsOfQuestions:(NSString*)questions options:(NSString*)options answer:(NSString*)answer;

-(NSString*)getQuestions;
-(NSString*)getOptions;
-(NSString*)getAnswer;

dbVals.m

#import "DbVals.h"

@implementation DbVals

-(void)setValsOfQuestions:(NSString*)questions options:(NSString*)options answer:(NSString*)answer
{
    questions_ = questions;
    options_ = options;
    answer_ = answer;
}

-(NSString*)getQuestions
{
    return questions_;
}

-(NSString*)getOptions
{
    return options_;
}

-(NSString*)getAnswer
{
    return answer_;
}

@end
  • 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-27T17:19:46+00:00Added an answer on May 27, 2026 at 5:19 pm

    Your dbVals.m setVals isn’t retaining the parameters. This obviously means, everything inside becomes deallocated once the function scope ends.
    Try changing it to something like

    -(void)setValsOfQuestions:(NSString*)questions options:(NSString*)options answer:(NSString*)answer
    {
        [questions_ release];
        [options_ release];
        [answer_ release];
        questions_ = [questions copy];
        options_ = [options copy];
        answer_ = [answer copy];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a desktop Mac OS X App that saves its very simple data
I'm developing a project for windows phone 7. It's very simple I guess but
I'm developing a very simple web site, with only one web page, but i
I'm developing a very simple but (hopefully) solid framework that just fits my needs.
I'm currently developing a very simple app with very basic syntax highlighting in a
I am developing a Rails app and need to automatically increment a very simple
I am currently developing a very simple database that tracks people and the company
I'm very new to Java but I've been developing a habit to use final
I've been experiencing very inconsistent results while developing an iPhone app and trying to
Well, I think I have a very basic doubt here: I'm developing an app

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.