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?
NSUserDefaults :
So, you shouldn’t really be using
NSUserDefaultsto 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
UITableViewappearing?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
HumanContact.m
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 aHumanContactobject:and populate the member variables appropriately:
This contact can then be added to a member variable (could be a single
HumanContactor 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 *)indexPathyou simply query your model for the information, instead ofNSUserDefaultsi.e
Hope this helps
edit
In your tableViewController (wherever you are parsing the xml) you need to have an array in the .h
Then in the .m:
in
viewDidLoadwhere you parse your xml:
Then in your tableViewCell
Book currentBook = [this.books objectAtIndex: indexPath.row];
NSString *telNum = currentBook.telNumber;
Remember that you are adding the
Bookto the array, and you ger a book back from the array.