Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-07-2012, 09:40 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 34
starsky is on a distinguished road
Default TBXML -- Not Loading Properly

Hey everyone,

I'm using TBXML to parse one xml file. Almost everything works well. It goes into the tableview and everything. There is one problem. The array only seems to be holding the final element and repeating it for however many number of other elements i have. I don't think that made too much sense so here is what I mean.

Code:
<thing>
<otherThing title = "hi">
<des> hi everyone</des>
</otherThing>
<otherThing title = "yea">
<des> sup</des>
</otherThing>
</thing>
It will repeat otherThing with the title of yea twice instead of putting both of them.

Here is my code.

Code:
- (void)load{

array= [[NSMutableArray alloc] initWithCapacity:10];

    // error var
    NSError *error = nil;
    
// Load and parse the books.xml file
tbxml = [TBXML tbxmlWithXMLFile:@"books.xml" error:&error];
    
    // if an error occured, log it
    if (error) {
        NSLog(@"Error! %@ %@", [error localizedDescription], [error userInfo]);

    } else {

        // Obtain root element
        TBXMLElement * root = tbxml.rootXMLElement;
        
        // if root element is valid
        if (root) {
            // search for the first author element within the root element's children
            TBXMLElement * author = [TBXML childElementNamed:@"otherThing" parentElement:root];
            
            // if an author element was found
            while (author != nil) {
                
                // instantiate an author object
                Author * anAuthor = [[Author alloc] init];
                
                // get the name attribute from the author element
                anAuthor.name = [TBXML valueOfAttributeNamed:@"title" forElement:author];
                
              
                
                // add our author object to the authors array
                [array addObject:anAuthor];
                
                // find the next sibling element named "author"
                author = [TBXML nextSiblingNamed:@"otherThing" searchFromElement:author];
            }
        }
    }
}


Any help would be more than appreciated.

Thanks!
starsky is offline   Reply With Quote
Old 02-07-2012, 11:25 AM   #2 (permalink)
Use [code] tags please
 
Join Date: Jun 2009
Location: Jacksonville, FL
Posts: 410
timle8n1 is on a distinguished road
Default

Hmm its not jumping out to me here - are you sure the problem is in the array and not in the tableview rendering?

What does your tableView:cellForRowAtIndexPath: method look like?
timle8n1 is offline   Reply With Quote
Old 02-07-2012, 02:00 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 34
starsky is on a distinguished road
Default

Here it is.

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
    }
	
	AppDelegate * appDelegate = [UIApplication sharedApplication].delegate;
	
	Author * anAuthor = [appDelegate.array objectAtIndex:indexPath.row];
    cell.textLabel.text = anAuthor.name;
	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
Thanks

Last edited by starsky; 02-07-2012 at 03:53 PM.
starsky is offline   Reply With Quote
Old 02-07-2012, 02:24 PM   #4 (permalink)
Use [code] tags please
 
Join Date: Jun 2009
Location: Jacksonville, FL
Posts: 410
timle8n1 is on a distinguished road
Default

I'm confused are these your actual methods?

Because load refers to anAuthor.name and tableView:cellForRowAtIndexPath: refers to anAuthor.title.

You should also release anAuthor after adding it to the array - unless you are using arc. And autorelease the cell in tableView:cellForRowAtIndexPath:
timle8n1 is offline   Reply With Quote
Old 02-07-2012, 03:07 PM   #5 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 34
starsky is on a distinguished road
Default

Quote:
Originally Posted by timle8n1 View Post
I'm confused are these your actual methods?

Because load refers to anAuthor.name and tableView:cellForRowAtIndexPath: refers to anAuthor.title.

You should also release anAuthor after adding it to the array - unless you are using arc. And autorelease the cell in tableView:cellForRowAtIndexPath:
Yeah I'm using arc. Sorry about that, it was supposed to say .name. I didn't have the code on hand when i initially typed this
starsky is offline   Reply With Quote
Old 02-07-2012, 03:12 PM   #6 (permalink)
Use [code] tags please
 
Join Date: Jun 2009
Location: Jacksonville, FL
Posts: 410
timle8n1 is on a distinguished road
Default

Quote:
Originally Posted by starsky View Post
Yeah I'm using arc. Sorry about that, it was supposed to say .name. I didn't have the code on hand when i initially typed this
Seriously - do not waste my time with code that isn't cut-and-paste from the actual codebase. Thats just rude.
timle8n1 is offline   Reply With Quote
Old 02-07-2012, 03:14 PM   #7 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 34
starsky is on a distinguished road
Default

Quote:
Originally Posted by timle8n1 View Post
Seriously - do not waste my time with code that isn't cut-and-paste from the actual codebase. Thats just rude.
chill.
starsky is offline   Reply With Quote
Old 02-07-2012, 03:21 PM   #8 (permalink)
Use [code] tags please
 
Join Date: Jun 2009
Location: Jacksonville, FL
Posts: 410
timle8n1 is on a distinguished road
Default

Quote:
Originally Posted by starsky View Post
chill.
Are you sure you want to cop an attitude with someone who WAS trying to help you. Okay fine then.
timle8n1 is offline   Reply With Quote
Old 02-07-2012, 03:28 PM   #9 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 34
starsky is on a distinguished road
Default

Quote:
Originally Posted by timle8n1 View Post
Are you sure you want to cop an attitude with someone who WAS trying to help you. Okay fine then.
I'm not getting an attitude. I honestly didn't mean to do that and I'm sorry, like I said.

All I said was chill, nothing with offensive intent.

The way you came across by saying I was wasting your time led me to believe you were pretty angry. Likewise, I said chill to potentially alleviate your anger.
starsky is offline   Reply With Quote
Old 02-07-2012, 03:41 PM   #10 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

This is getting good; hang on while I make some popcorn.

Seriously, though, I do agree with timle8n1; you should post only actual code, not "remembered" code. Because there's no way anyone could do that accurately, and examining it therefore has no value.

So hopefully you'll update the thread with real code. In the meantime, have you tried the obvious step of logging your array at the end of your load method to see what's in it?
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 02-07-2012, 03:53 PM   #11 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 34
starsky is on a distinguished road
Default

Quote:
Originally Posted by dljeffery View Post
This is getting good; hang on while I make some popcorn.

Seriously, though, I do agree with timle8n1; you should post only actual code, not "remembered" code. Because there's no way anyone could do that accurately, and examining it therefore has no value.

So hopefully you'll update the thread with real code. In the meantime, have you tried the obvious step of logging your array at the end of your load method to see what's in it?
Will do, and I'm really sorry about that. I'll fix it.

Yes, I have. I probably should have included that as well.

I get the same thing I get in the tableview. However, because it is logged, I see a little more. Let me show you what I mean.

Referring to my original post:

Code:
Array: (
    "hi everyone"
)
 Array: (
    "sup",
    "sup"
)
Thanks,
starsky is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 399
14 members and 385 guests
7twenty7, chiataytuday, cristofercolmbos, fiftysixty, gmarro, iOS.Lover, KennyChong, kilobytedump, Matrix23, raymng, ryantcb, stanny, UMAD, xerohuang
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,669
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dedeys78
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:18 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0