Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.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 07-07-2009, 08:52 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 87
Question TableView Drill Down issue (with XML)

I am trying to do a drill down in my app where the first table view displays the title of books. Then when you select the title it takes you to a drill down of the chapters in that specific book. Then when you select the chapter it will go into a detail view.

I have managed to get the initial table view set up that displays my book titles however when i try to build in the second table view for my chapters the table will display ALL chapters of ALL the books instead of jsut the chapters that are part of the specific book that i selected....

(I have been working on this for 4 hours now!)

Below is what i believe to be the relevant code. Let me know if you guys need more and i can paste it in...

Oh i forgot to mention that this is all coming from a local server with XML code! so i will also paste in relevant data on the XML code.

XML file:
<?xml version="1.0" encoding="UTF-8"?>
<Books>
<Book id="1">
<title>CircumferenceTest</title>
<Chapter>Chapter1</Chapter>
<Chapter>Chapter2</Chapter>
<author>Nicholas Nicastro</author>
<summary>Eratosthenes and the Ancient Quest to Measure the Globe.</summary>
</Book>
<Book id="2">
<title>Copernicus Secret</title>
<Chapter>Chapter6</Chapter>
<Chapter>Chapter7</Chapter>
<author>Jack Repcheck</author>
<summary>How the scientific revolution began</summary>
</Books>
pmvinuelas is offline   Reply With Quote
Old 07-07-2009, 08:55 PM   #2 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 87
Question

XMLParser.m
//Parsing the Start of an Element

- (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: @"Chapters"])
{
//Initialize the Array
appDelegate.chapters = [[NSMutableArray alloc] init];
}

else if([elementName isEqualToString: @"Book"])
{
//Initialize the book
aBook = [[Book alloc] init];

//Extract the attribute here
aBook.bookID = [[attributeDict objectForKey:@"id"] integerValue];

NSLog(@"Reading id value :%i", aBook.bookID);
}
else if([elementName isEqualToString:@"Chapter"])
{
//Initialize the book
aChapter = [[Book alloc] init];

//Extract the attribute here
aChapter.chapter = [[attributeDict objectForKey:@"id"] integerValue];

NSLog(@"Reading id value :%i", aBook.bookID);
}


NSLog(@"Processing Element: %@", elementName);

}
// Parsing an elements value

- (void)parser: (NSXMLParser *)parser foundCharactersNSString *)string
{
if(!currentElementValue)
currentElementValue = [[NSMutableString alloc] initWithString:string];
else
[currentElementValue appendString:string];

NSLog(@"Processing Value: %@", currentElementValue);
}

//Parsing the end of an element

- (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 books elemnt
//If we encounter the book element however we want to add the book object
//to the array and release the object
else if([elementName isEqualToString:@"Book"])
{
[appDelegate.books addObject:aBook];

[aBook release];
aBook = nil;
}
else
[aBook setValue:currentElementValue forKey:elementName];

[currentElementValue release];
currentElementValue = nil;

}
RootViewController.m (This is for my book titles)

- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{

srvController = [[SecondRootViewController alloc] initWithNibName:@"SecondRootView" bundle:[NSBundle mainBundle]];

//Something here will get you to the second view details!!!
/*
Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];

srvController.aBook = aBook;

*/
//Prepare to tableview.
SecondRootViewController *srvController = [[SecondRootViewController alloc] initWithNibName:@"SecondRootViewController" bundle:[NSBundle mainBundle]];


//Push the new table view on the stack
[self.navigationController pushViewController:srvController animated:YES];

}



SecondRootViewController.m (this is for my chapters)

// Customize the appearance of table view cells.
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
pmvinuelas 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


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Online Users: 295
23 members and 272 guests
applezinga, arossco, bono_aem, DonomaGames, Erle, falcon76, Gi-lo, irishkiwi, iTrackiGiveaway, Locker, majjaz, Meoz, mikeyb, mmdumi, nibby, Nicsoft, Nuncha, oldmicah, Rainer, RoMa, scotopia, themaster, Vita Alex
Most users ever online was 779, 05-11-2009 at 09:55 AM.
» Stats
Members: 24,282
Threads: 39,076
Posts: 171,351
Top Poster: smasher (2,575)
Welcome to our newest member, FANFAN
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:20 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0