Note that there are some explanatory texts on larger screens.

plurals
  1. POconnect XML file to Label (objective-C)
    primarykey
    data
    text
    <p>I have an <code>UIViewController</code> page with one button and one <strong>label</strong> . I added xml parser on my project and everything works (I test it in console), right now I want to connect my XML file to my label to just get one attribute of XML file(for test). My question is how can I connect XML to my label. Would you please give me some hint for implementing this?</p> <p>I'm new to objective-C</p> <p>Here is my code:</p> <p>I just want to see how we can connect xml file to label</p> <pre><code> - (void)viewDidLoad { //appDelegate = (testAppDelegate *)[[UIApplication sharedApplication] delegate]; label.textColor = [UIColor greenColor]; // label.text = aBook.title; //it not working, I don't know what should I write to get one // element of xml file to this label or first element of xml file [super viewDidLoad]; } </code></pre> <p>Here is my xml file</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;Books&gt; &lt;Book id="1"&gt; &lt;title&gt; Circumference&lt;/title&gt; &lt;author&gt;Nicholas Nicastro&lt;/author&gt; &lt;summary&gt;Eratosthenes and the Ancient Quest to Measure the Globe.&lt;/summary&gt; &lt;/Book&gt; &lt;Book id="2"&gt; &lt;title&gt;Copernicus Secret&lt;/title&gt; &lt;author&gt;Jack Repcheck&lt;/author&gt; &lt;summary&gt;How the scientific revolution began&lt;/summary&gt; &lt;/Book&gt; &lt;Book id="3"&gt; &lt;title&gt;Angels and Demons&lt;/title&gt; &lt;author&gt;Dan Brown&lt;/author&gt; &lt;summary&gt;Robert Langdon is summoned to a Swiss research facility to analyze a cryptic symbol seared into the chest of a murdered physicist.&lt;/summary&gt; &lt;/Book&gt; &lt;Book id="4"&gt; &lt;title&gt;Keep the Aspidistra Flying&lt;/title&gt; &lt;author&gt;George Orwell&lt;/author&gt; &lt;summary&gt;A poignant and ultimately hopeful look at class and society, Keep the Aspidistra Flying pays tribute to the stubborn virtues of ordinary people who keep the aspidistra flying. &lt;/summary&gt; &lt;/Book&gt; </code></pre> <p></p> <p>and if it's needed here is my parser class:</p> <pre><code>- (Presentation1NameXML *) initXMLParser { appDelegate = (testAppDelegate *)[[UIApplication sharedApplication] delegate]; return self; } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict { if([elementName isEqualToString:@"Books"]) { //Initialize the array. appDelegate.books = [[NSMutableArray alloc] init]; } else if([elementName isEqualToString:@"Book"]) { //Initialize the book. aBook = [[Presentation1Name alloc] init]; //Extract the attribute here. aBook.bookID = [[attributeDict objectForKey:@"id"] integerValue]; NSLog(@"Reading id value :%i", aBook.bookID); } NSLog(@"Processing Element: %@", elementName); } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if(!currentElementValue) currentElementValue = [[NSMutableString alloc] initWithString:string]; else [currentElementValue appendString:string]; NSLog(@"Processing Value: %@", currentElementValue); } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if([elementName isEqualToString:@"Books"]) return; //There is nothing to do if we encounter the Books element here. //If we encounter the Book element howevere, we want to add the book object to the array // and release the object. if([elementName isEqualToString:@"Book"]) { [appDelegate.books addObject:aBook]; aBook = nil; } else [aBook setValue:currentElementValue forKey:elementName]; currentElementValue = nil; } @end </code></pre> <p><strong>Edit:</strong> </p> <p>when I used </p> <pre><code> NSLog(@"%@", aBook.title); I got NULL </code></pre> <p><strong>Edit</strong></p> <p>in some sample that I saw they have something like this also</p> <pre><code> Book *aBook = [appDelegate.books objectAtIndex:indexPath.row]; </code></pre> <p>since they use it in tableView But I don't have any table what should I write instead of objectAtIndex:indexPath.row];</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload