ios - Where to Initialize NSMutableArray to Prevent Erasure -


I am trying to create an NSMutableArray in which a float (has been changed to NSINtega) has been added to it when a button Is pressed. The button is connected to a timer controller and the block code in its implementation file is as follows (if you can ignore the statement in case of this question):
  - (IBAction) timeSaveButton: (UIButton *) Sender {if ([self.timerStartOrStop.titleLabel.text isEqual: @ "Start"]) {Recorded Times * myTimes = [[Record Times alloc] init]; [MyTimes addNewTime: self.timerTime]; }}   

In the "RecordedTimes" class, this refers to declaring NSMutableArray and "addNewTime" method in .h files

  @interface RecordedTimes : NSObject @ Property (Nonomatic) NSMUTABLEERE * Time entered; - (zero) addANewTime: (float) timer; @end   

its implementation file

  @implementation record time - (zero) addANewTime: (float) timerime {NSMutableArray * myTimes = [[NSMutableArray alloc] in this]; [MyTimes addObject: [NSString stringWithFormat: @ "% f", TimerTime]]; } @end   

The problem is that every time I save a new time, the array only clears and stores the most recent timer time. I understand that this is because my viewController (and addNewTime method) launches the array every time, so that it removes its content, how to fix that problem and instead where the method of initializing the array is I am confused.

Please expand your response. I'm a newbie for XCode and Objective-C. Thank you.

You have declared the NSMutableArray property to the time entered But never opened it for an empty array anywhere convenient, such as init method, you can start it:

  - ( Id) init {self = [super init]; If (self) {self.recordedTimes = [[NSMutableArray alloc] init]; } Healthy return; }   

Then add addANewTime: to:

  - (zero) addANewTime: (float) timerime {[auto. Recorded Times addObject: [NSString stringWithFormat: @ "% f", TimerTime]]; }   

This ensures that your shaky array property is started once (because once you start your object in init ), And then you are called addANewTime: each time.


In addition, you are called the Recorded Times object every time the time saving button: method. You want to follow the same pattern, and want to store it on your visual controller class as a property and then set it in the same way as the viewDidLoad method. On one side: You've probably noticed that you can specify a int (or, typically, a primitive , non-object type) You can not store in the NSMutableArray object as timerime in NSNumber as the [NSNumber numberWithInt: timerTime] You can consider changing and storing in that array instead of that string.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -