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

  • SEARCH
  • Home
  • 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 6709285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:51:45+00:00 2026-05-26T07:51:45+00:00

In this method I add the content of UITextFields, images and other strings in

  • 0

In this method I add the content of UITextFields, images and other strings in a sqlite database. Everything works fine. I mean, when i press the “Add” button, the “OK” image appear, the sound play and all the contents are added to the database (I can check restarting the application). But after all of this, I have this error in the “main.m”

This is the method:

-(IBAction)addItem:(id)sender { //gestione pulsante aggiunta elemento
    if (([itemNameField.text length] == 0) || ([priceField.text length] == 0) || ([priceField.text doubleValue] == 0.0) || ((incomeOutcome.selectedSegmentIndex != 0) && (incomeOutcome.selectedSegmentIndex != 1))) {
        if ([itemNameField.text length] == 0) {
        statusLabel.text = [[NSString alloc] initWithFormat: @"Specificare un nome."];
        } else if (([priceField.text length] == 0) || ([priceField.text doubleValue] == 0.0)) {
            statusLabel.text = [[NSString alloc] initWithFormat: @"Specificare un prezzo."];
        } else if ((incomeOutcome.selectedSegmentIndex != 0) && (incomeOutcome.selectedSegmentIndex != 1)) {
            statusLabel.text = [[NSString alloc] initWithFormat: @"Specificare \"Income/Outcome\" ."];            
        }
        if (!categoriaLabel.hidden) {
            [self hideThemAll];
        }
        [incomeOutcome setSelectedSegmentIndex:-1];
        statusLabel.hidden = NO;
        error = true;
        [self playSound];
        [ok setImage:[UIImage imageNamed:@"error.png"]];
        ok.hidden = NO;
        return;
    }
    //apriamo il database
    sqlite3 *db;
    int dbrc; //Codice di ritorno del database (database return code)
    iWalletAppDelegate *appDelegate = (iWalletAppDelegate*) [UIApplication sharedApplication].delegate;
    const char *dbFilePathUTF8 = [appDelegate.dbFilePath UTF8String];
    dbrc = sqlite3_open(dbFilePathUTF8, &db);
    if (dbrc) {
        NSLog(@"Impossibile aprire il Database!");
        return;
    }
    //database aperto! Inseriamo valori nel database.
    sqlite3_stmt *dbps; //Istruzione di preparazione del database
    NSString *insertStatementsNS;
    if (incomeOutcome.selectedSegmentIndex == 0) {
        insertStatementsNS = [NSString stringWithFormat: @"insert into \"shoppinglist\" (item, price, groupid, incout, path,  dateadded) values (\"%@\", \"%@\", \"Entrata\", %d, \"%@\", DATETIME('NOW'))", itemNameField.text, priceField.text, incomeOutcome.selectedSegmentIndex, imagePath];
    } else if ([categoryNameField.text length] != 0) { 
        insertStatementsNS = [NSString stringWithFormat: @"insert into \"shoppinglist\" (item, price, groupid, incout, path, dateadded) values (\"%@\", \"%@\", \"%@\", %d, \"%@\", DATETIME('NOW'))", itemNameField.text, priceField.text, categoryNameField.text, incomeOutcome.selectedSegmentIndex, imagePath]; 
    } else { 
        insertStatementsNS = [NSString stringWithFormat: @"insert into \"shoppinglist\" (item, price, groupid, incout, path, dateadded) values (\"%@\", \"%@\", \"Varie\", %d, \"%@\", DATETIME('NOW'))", itemNameField.text, priceField.text, incomeOutcome.selectedSegmentIndex, imagePath];
    }
    const char *insertStatement = [insertStatementsNS UTF8String];
    dbrc = sqlite3_prepare_v2(db, insertStatement, -1, &dbps, NULL);
    dbrc = sqlite3_step(dbps);

    //faccio pulizia rilasciando i database
    sqlite3_finalize(dbps);
    sqlite3_close(db);

    // Pulisci i campi e indica successo nello status
    statusLabel.hidden = NO;
    statusLabel.text = [[NSString alloc] initWithFormat: @"Aggiunto %@", itemNameField.text];

    itemNameField.text = @"";
    priceField.text = @"";
    categoryNameField.text = @"";
    imagePath = @"";
    [incomeOutcome setSelectedSegmentIndex:-1];
    error = false;
    [self hideThemAll];
    [self playSound];
    [ok setImage:[UIImage imageNamed:@"ok.png"]];
    ok.hidden = NO;
    nome = @"";
    prezzo =@"";
    [photoPreview setImage:[UIImage imageNamed:@"noPhoto.png"]];
    [[self parentViewController]dismissModalViewControllerAnimated:YES];
}    

EDIT

Thanks to Isaac I (maybe) found the issue: I wasn’t retaining the picture I took from the camera.

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    int r = arc4random() % 9999;
    NSDate *date = [NSDate date];
    NSString *photoName = [dateNameFormatter stringFromDate:date];
    photoName = [photoName stringByAppendingString:[NSString stringWithFormat:@"%d", r]];

    if (imagePath) {
        [imagePath release];
    }
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", photoName]];
    [imagePath retain];

    UIImage *picture = [info objectForKey:UIImagePickerControllerOriginalImage];

    // ----- CODE FOR SCALE THE IMAGE ----- //
    if (picture.size.width == 1936) {
        picture = [picture scaleToSize:CGSizeMake(480.0f, 720.0f)];
    } else {
        picture = [picture scaleToSize:CGSizeMake(720.0f, 480.0f)];
    }

    photoPreview.image =  picture;

    photoPreview.contentMode = UIViewContentModeScaleAspectFit;

    CGRect frame = photoPreview.frame;
    if (picture.size.width == 480) {
        frame.size.width = 111.3;
        frame.size.height =167;
    } else {
        frame.size.width = 167;
        frame.size.height =111.3;
    }
    photoPreview.frame = frame;
    // ----- ----- - END CODE - ----- ----- //    

    NSData *webData = UIImagePNGRepresentation(picture);
    CGImageRelease([picture CGImage]);
    [webData writeToFile:imagePath atomically:YES];
    [picture retain]; // <-- This little thing here!
    //imgPicker = nil;
}

Now it works! But if you can see other problems, please let me notice them.

  • 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-26T07:51:46+00:00Added an answer on May 26, 2026 at 7:51 am

    Typically an EXC_BAD_ACCESS occurs when you are trying to access memory that has been deallocated. In your code sample, I don’t see any [object release] calls (that’s another problem entirely, unless you happen to be using ARC). But my guess it that this error is the result of a call that is being made outside of the scope of this method – something is being released prematurely.

    You could paste your entire class, or, consider using the Instruments tool ‘Zombies’ to identify the dangling pointer which is (probably) causing this.

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

Sidebar

Related Questions

The error is this: The method add(String, int) in the type DataNode is not
So, I have implemented this method to add a footer to my table view:
I was using the Add class method $(select[name=' + ABC+ i + ']).addClass('addBorder'); This
I'm using the method described by Josh in this question to add a toolbar
i have written a method in java like this public boolean ADD(String ID,String Name,String
This method works as expected - it creates a JTree with a root node
So I have a method in a reservation model called add_equip. This method does
This method that draws my tiles seems to be quite slow, Im not sure
This method is working totally right in matlab. but, when I compiled it in
With this method declaration (no overloads): void Method(double d) { // do something with

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.