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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:44:33+00:00 2026-05-13T07:44:33+00:00

Been searching for the answer to this for a while now and I think

  • 0

Been searching for the answer to this for a while now and I think due to the nature of my array set up, I may be searching for the wrong answer!

I have a class which handles adding items to my array:

// Item.h
@interface Item : NSObject {
    NSString *name;
    NSNumber *seconds;
}

@property(nonatomic,copy) NSString *name;
@property(nonatomic,copy) NSNumber *seconds;

- (id)initWithName:(NSString *)n seconds:(NSNumber *)sec;

@end

and…

//item.m

@implementation Item
@synthesize name, seconds;


- (id)initWithName:(NSString *)n seconds:(NSNumber *)sec {
    self.name = n;
    self.seconds = sec;
    return self;
}
@end

So to add an item, I use

Item *item1 = [[Item alloc] initWithName:@"runnerA" seconds:[NSNumber numberWithInt:780]];

I have some code which allows a user to edit a textfield (runner name) and the time which is a UIdatepicker set to hours and minutes. In the save method, that’s working fine. It’s the UPDATE that I cannot get to work. I’ve tried alsorts! Here’s the code at the moment…

mainAppDelegate *appDelegate = (mainAppDelegate *)[[UIApplication sharedApplication] delegate];    
Item *item = [[Item alloc] initWithName:inputName.text seconds:[NSNumber numberWithInt:secs]];
[appDelegate.arrItems replaceObjectAtIndex:rowBeingEdited withObject:item];

The above is simply adding a new item to the array (which is what I don’t want). I’m not sure how to replace values. At the function, I have the row I need to update (rowBeingEdited) and the fields inputName.text and secs are both OK. (NSLog out confirms this).

How do I use the replaceObjectAtIndex to actually replace it with the values?! It’s driving me mad now!!

  • 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-13T07:44:34+00:00Added an answer on May 13, 2026 at 7:44 am

    Since you are simply trying to edit a particular row, why not use those property accessors that you already have set up in Item? It would look something like this:

    Item *item = (Item *)[appDelegate.arrItems objectAtIndex:rowBeingEdited];
    [item setName:inputName.text];
    [item setSeconds:[NSNumber numberWithInt:secs]];
    

    An a side note, are you using garbage collection, or do you manually release the Item objects that you create when adding items to the array? If you are doing it manually, it should look like this:

    Item *item1 = [[Item alloc] initWithName:@"runnerA"
                                     seconds:[NSNumber numberWithInt:780]];
    [appDelegate.arrItems addObject:item1];
    [item1 release];
    

    This follows the rule of thumb: if you alloc, copy or retain anything, you must also release it. Note that this works because the array will retain the item when it is added.

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

Sidebar

Related Questions

I've been searching for a while but couldn't find a definite answer to this
I have been searching for the solution to this problem for a while and
I've been searching around for this and cannot seem to find a solid answer.
I have been searching for info on this to no avail. The context of
Been searching for a good coverage tool for a while now. I'm with VC++
For a little while now I've been searching for a code to get URL's
I've been searching on this but can't seem to find an exact answer (most
I have been searching everywhere for the following functionality in Lisp, and have gotten
I've been searching around, and I haven't found how I would do this from
I have been searching high and low for a way to get my silverlight

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.