C.Johns
C.Johns

Reputation: 10245

how to return a row count for tableview from NSXMLParserdelegate methods?

I am currently using the ASIHTTPRequest wrapper to connect to my database though a php script, basicly it queries the database then returns the result set in an xml format.

from there i instantiate my parser method which inturn passes all the requiered info to the NSXMLParserDelegate methods

//..
parser:didStartElement:namespaceURI:qualifiedName:attributes:
//..
parser:foundCharacters:
//..
parser:didEndElement:namespaceURI:qualifiedName:
//..

The data is first of all passed through a NSMutableData variable when the initial steam of data comes down.

I then have an if statment in my parser:didStartElement:namespaceURI:qualifiedName:attributes: that passes all the data into the string on the basis of the condition

if ([elementName isEqual:@"item"]) {
        // NSLog(@"Found title!");
        itemString = [[NSMutableString alloc] init];
    }

from here I am wondering how I set the row count of the tableview inside the numberOfSectionsInTableView method? what variable would I call count on or would I have to create something else?

Upvotes: 0

Views: 741

Answers (2)

Sergnsk
Sergnsk

Reputation: 3303

There is great tutorial for parsing XML in Apple Sample Source Code It's called SeismicXML

http://developer.apple.com/library/ios/#samplecode/SeismicXML/Listings/Classes_RootViewController_m.html#//apple_ref/doc/uid/DTS40007323-Classes_RootViewController_m-DontLinkElementID_8

in your question you have the error: numberOfSectionsInTableView didn't return the row count - it's return sections count. In most casesif you have ordinary tableview it should return 1.

and this code return number of rows in this section

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [YOUR_ARRAY count];
}

Upvotes: 1

Mohammad
Mohammad

Reputation: 1666

If I am not misunderstanding you question following will help.

1 Hope you are already saving all values of items in some array in elementDidEnd method.

2 Write some code like following.
if([parser parse]){ [tableView reloadData]; }

This will reload table once parsing is done.

3 Return count of array in which you stored all the item values and fill the table with that array.

Please post if you need any more help.

Upvotes: 0

Related Questions