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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:46:09+00:00 2026-05-15T01:46:09+00:00

I have a problem. This is my code. When i try to use the

  • 0

I have a problem.
This is my code.
When i try to use the IBAction SavePosition the “arrayPosition” isn’t update.
Else if i initialize the “arrayPosition” in “SavePosition” the value is stored in the array.
Why this anomaly?

#import <UIKit/UIKit.h>

@interface AccelerometroViewController : UIViewController <UIAccelerometerDelegate, UITextFieldDelegate, UIAlertViewDelegate>{

    //.....     

    NSMutableArray *arrayPosizioni;
    NSMutableArray *arrayPosizioniCorrenti;

    NSString *nomePosizioneCorrente;

}

-(IBAction)salvaPosizione;


//...
@property (nonatomic, assign)   NSMutableArray      *arrayPosizioni;
@property (nonatomic, assign)   NSMutableArray      *arrayPosizioniCorrenti;

@property (nonatomic, assign)   NSString      *nomePosizioneCorrente;

@end



#import "AccelerometroViewController.h"
#import "Position.h"

@implementation AccelerometroViewController



float actualX;
float actualY;
float actualZ;


@synthesize arrayPosition;
@synthesize arrayCurrentPosition;

@synthesize nameCurrentPosition;

    -(id)init {
        self = [super init];
        if (self != nil) {
            arrayPosition = [[NSMutableArray alloc]init];
            arrayCurrentPosition = [[NSMutableArray alloc]init];
            nameCurrentPosition = [NSString stringWithFormat:@"noPosition"]; 
            actualX = 0;
            actualY = 0;
            actualZ = 0;
        }
        return self;
    }


    -(void)updateTextView:(NSString*)nomePosizione
    {
        NSString *string = [NSString stringWithFormat:@"%@", nameCurrentPosition];
        textEvent.text = [textEvent.text        stringByAppendingString:@"\n"];
        textEvent.text = [textEvent.text        stringByAppendingString:string];
    }


    -(IBAction)savePosition{

        Posizione *newPosition;
        newPosition = [[Position alloc]init];

        if([newPosition     setValue:(NSString*)fieldNomePosizione.text:(float)actualX:(float)actualY:(float)actualZ]){
       //setValue is a method of Position. I'm sure that this method is correct
            UIAlertView *alert = [[UIAlertView  alloc] initWithTitle:@"Salvataggio Posizione" message:@"Posizione salvata con successo" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
            [alert  show];
            [alert  release];           
            [arrayPosition  addObject:newPosition];
        }
        else{
            UIAlertView *alert = [[UIAlertView  alloc] initWithTitle:@"Salvataggio osizione" message:@"Errore nel salvataggio" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
            [alert show];
            [alert release];
        }
   }
  • 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-15T01:46:09+00:00Added an answer on May 15, 2026 at 1:46 am

    Whats going on?

    I bet you’re creating your view controller inside a xib file?

    If you set a breakpoint inside your init method on the line

    arrayPosition = [[NSMutableArray alloc]init];
    

    I bet it never runs. This means that when you get to the line

    [arrayPosition  addObject:newPosition];
    

    arrayPosition is still nil so nothing happens.

    How to fix it?

    If you’re initializing a UIViewController it’s either called inside initWithNibName:bundle: if you’ve created it in code or in initWithCoder: if it’s created inside a xib file.

    You need to do something like this :

    - (void) initialise {
        arrayPosition = [[NSMutableArray alloc] init];
        arrayCurrentPosition = [[NSMutableArray alloc] init];
        nameCurrentPosition = @"noPosition"; 
        actualX = 0;
        actualY = 0;
        actualZ = 0;
    }
    
    - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle {
        if (self = [super initWithNibName:nibName bundle:bundle]) {
            [self initialise];
        }
        return self;
    }
    
    - (id)initWithCoder:(NSCoder *)decoder {
        if (self = [super initWithCoder:decoder]) {
            [self initialise];
        }
        return self;
    }
    

    This will call initailise regardless of how the view controller is created.

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

Sidebar

Related Questions

I have a prepared statement: PreparedStatement st; and at my code i try to
... <tr> <td>222</td> </tr> <tr> <td>333 222</td> </tr> ... And I have this code
Does anyone else get this problem or know a solution / workaround I could
This is my code: public class RegularPolygon { public int VertexCount; public double SideLength;
I have a next problem. I need to represent a pressed keys combination in
Hi dear friends i have 495 cells and a textField for inserting number and
I export try.jar file using 32 bit java libraries. On the client site, I
First of all, as usual, thanks to all for the great support from the
Im attempting to bind to the output of a method. Now I've seen examples
can i somehow find all functions/macros that take a specific type of parameter ?

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.