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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:19:38+00:00 2026-05-15T22:19:38+00:00

Somehow its data is not transferring so I am using other method for displaying

  • 0

Somehow its data is not transferring so I am using other method for displaying but is this good for memory management ??

if ( [elementName isEqualToString:@"telnumber"]) {

   NSLog(@"Processing Value: %@", currentElementValue);
   NSUserDefaults *tel = [NSUserDefaults standardUserDefaults];
   [tel setObject:currentElementValue forKey:@"keyTotel"];
   return;
}

and then in detail view i am using this

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSLog(@"String = %@",aBook.telnumber);
    NSUserDefaults *get = [NSUserDefaults standardUserDefaults];
    NSString *mytel = [get stringForKey:@"keyTotel"];
    NSLog(@" LOCAL phone   is %@",mytel); 
}

So for all 6 elements on XML I have to follow same process is that good enough?

  • 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-15T22:19:39+00:00Added an answer on May 15, 2026 at 10:19 pm

    NSUserDefaults :

    The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an application to customize its behavior to match a user’s preferences. For example, you can allow users to determine what units of measurement your application displays or how often documents are automatically saved. Applications record such preferences by assigning values to a set of parameters in a user’s defaults database. The parameters are referred to as defaults since they’re commonly used to determine an application’s default state at startup or the way it acts by default

    So, you shouldn’t really be using NSUserDefaults to hold anything other than default application settings (and certainly not for holding temporary variables).

    I assume you are parsing your XML file at some point in the application, prior to the UITableView appearing?

    A better (simple) approach would be to have another class that represents the object being described in the XML, and populating this object with the data extracted from the XML. (or populate n objects for n entries in the xml).

    So, if your XML describes a contact in your app:
    HumanContact.h

    @interface HumanContact : NSObject {
    NSString* firstName;
    NSString* surname;
    NSString* telephoneNumber;
    //etc...
    
    }
    
    @property (nonatomic, retain) NSString* firstName;
    @property (nonatomic, retain) NSString* surname;
    @property (nonatomic, retain) NSString* telephoneNumber;
    

    HumanContact.m

    #import "HumanContact.h"
    
    @implementation HumanContact {
    
    @synthesize firstName, surname, telephoneNumber;
    
    // all default init + dealloc methods etc (remember to release the properties etc)
    }
    

    Now this object exists as a method of containing all data about a contact. It is the Model in your MVC

    Externally, when you parse your XML, instead of adding a key for each item in NSUserDefaults, for each record in the XML you would create a HumanContact object:

    HumanContact *contact = [[HumanContact init] alloc];
    

    and populate the member variables appropriately:

    if ( [elementName isEqualToString:@"telnumber"]) {
    
    contact.firstName = currentElementValue;
    
    }
    //  etc for remaining attributes
    

    This contact can then be added to a member variable (could be a single HumanContact or an array of them (more likely)).

    Once you’ve parsed the XML you have a local representation of this information that can be accessed anywhere in the class (and passed to other classes very simply).

    In your (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath you simply query your model for the information, instead of NSUserDefaults

    i.e

    (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HumanContact *curContact = [arrayOfContacts getItemAtIndex: indexPath.row];
    cel.text = curContact.telephoneNumber;
    //...
    }
    

    Hope this helps

    edit

    In your tableViewController (wherever you are parsing the xml) you need to have an array in the .h

    @interface FooTableViewController
    {
      NSMutableArray *books;
    }
    
    @property (nonatomic, retain) NSMutableArray *books;
    

    Then in the .m:

    @synthesize books;
    

    in viewDidLoad

    self.books = [[[NSMutableArray alloc] init] autorelease];
    

    where you parse your xml:

    book.telNumber = currentElement;
    [self.books addItem:book]; // array is of books, so add the whole thing
    

    Then in your tableViewCell
    Book currentBook = [this.books objectAtIndex: indexPath.row];
    NSString *telNum = currentBook.telNumber;

    Remember that you are adding the Book to the array, and you ger a book back from the array.

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

Sidebar

Ask A Question

Stats

  • Questions 461k
  • Answers 461k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The hard way The Rails development log file should contain… May 16, 2026 at 12:13 am
  • Editorial Team
    Editorial Team added an answer Error is generated for line tc.set_activeTabIndex(0); We don't have built-in… May 16, 2026 at 12:13 am
  • Editorial Team
    Editorial Team added an answer Just as a note, crosstools did say it could run… May 16, 2026 at 12:13 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.