tags:

views:

42

answers:

3

can i parse my XML in this method

Blockquote

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

// here some instance of XMLparser ?? }

Blockquote

like whenevrr uer press table cell then for detail view i want to pull data at that time only and for that specfic only as i have 8k data so i dont want to parse other data

A: 

I've used TouchXML and NSURLConnection in the past for doing these kind of things. You'll probably want to use the asynchronous methods so you don't block the GUI thread during the fetches.

sdolan
A: 

You have to be careful about runtime performance. If the parse runs really fast, like 50 - 100 ms, it is kind of acceptable performance for me. If it runs too long, like > 1 second, it is absolutely sure that you shouldn't put parsing in that method.

If you talk about pulling data from network and parsing it, it is quite risky and slow for me. If you use synchronous, it will block the UI, if you use asynchronous, what will happen when user going to detail view and don't see anything. If it is just like update old data, it is acceptable to use asynchronous

vodkhang
then i have no option what to i have to show detail view with all details .. earier i was loading all the data and it was working fine but since i have 8000 data so i cant parse whole xml thats why i am thinking of this process i paresed xml in that method but its working only for 1st time when i come back form detail view and press again table cell its just crashes and i am getting this*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (3) beyond bounds (0)'plz see
ram
i am using SQL for inital page this sql is having ID then i am using this ID in - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {//XML parisn here based on ID }
ram
if there is any other way then let me know how should i parse those XML either by ID on tablecell click or parsing whole xml but data is 8000
ram
The exception tells me that it has nothing to do with xml or sql or parsing one or multiple times. Do you use any array there, are you sure that you don't get something out of the array. Like the array has 2 elements and you say [array objectAtIndex:2] ?
vodkhang
i am uisng this Book *aBook = [appDelegate.books objectAtIndex:indexPath.row]; bdvController.aBook = aBook;
ram
what should i do to get the ID from database i am using aBook.id to store id from database
ram
Can you double check to see how many books in the appDelegate.books using [appDelegate.books count]. I think the storing and getting id for aBook has nothing wrong
vodkhang
see in this method- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];}now again- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {i am calling thisBook *aBook = [appDelegate.books objectAtIndex:indexPath.row]; bdvController.aBook = aBook; NSString *addurl =aBook.id;// to pull all the data for detail viewi think if somehow i got the ID then i am done}
ram
if its array error then how to make large array???
ram
hey i my [appDelegate.books count] is each time inc by 109 , 19,29,39 ??? how to solve this
ram
Can you show me the books array code, where do you init it? Where do you populate it?
vodkhang
i am using it in 3-4 time 1 in xml parsingif ( [elementName isEqualToString:@"results"]) { aBook = [[Book alloc] init]; //NSLog(@"found rootelement"); return; }// 1 in SQL qurey Book * aBook = [[Book alloc] init];/// and thenin those 2 tables
ram
but you didn't put aBook into books, right? I mean the books array, where is it?
vodkhang
you mean this [books addObject:aBook];its only in sql query while(sqlite3_step(compiledStatement) == SQLITE_ROW) {[books addObject:aBook];}
ram
vodkhang plz see this :(
ram
while(sqlite3_step(compiledStatement) == SQLITE_ROW) { Book * aBook = [[Book alloc] init]; // NSString *id = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)]; aBook.id = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)]; aBook.name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]; aBook.cuisine = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 7)]; [books addObject:aBook];[aBook release];}
ram
Ok, I am here. Just busy for a while
vodkhang
So, the books array look correctly. Can you print out the elements of books after that while loop. Just to check if after running the while loop, there are some elements there.
vodkhang
ok will do that but in the meawhile i checkd my arry value is 9 only if i am not parsing XML ..if i parse XML and then if ( [elementName isEqualToString:@"restra"]) { aBook = [[Book alloc] init]; //NSLog(@"found rootelement"); return; }then my values keep inc 9 , 19 , 29 but without this i cant pasre xml
ram
wow did it awsome i love you :-) thanks for being here i admire you :-) lets go for beer tonight whowwwwwwwwwwwwwwwww
ram
hey but after parsing when i go to detail view NSLog(@"String = %@",aBook.telnumber);value is null :( but xml is parsed
ram
i am using same Book class for both sql and XML
ram
hey i can see correct value NSLog(@"Processing Value: %@", currentElementValue);but while passing to detail view its null
ram
plz see this i am on last stage :(
ram
ok, I just back from lunch
vodkhang
So, to summarise: you get the telNumber of aBook null but you already parsed the xml for that. And in the list view, the currentElementValue is not null, but when you go to detail view, it becomes null, right?
vodkhang
Give me the code you pass the currentElementValue into the detailView. Also, double check about memory management, do you overuse any release or autorelease method, which cause the object to go die?
vodkhang
ok first of all if i use this if ( [elementName isEqualToString:@"telephone"]) { [appDelegate.books addObject:aBook]; [aBook release]; aBook = nil; return; }then my [appDelegate.books count] keep inc 1 each time any way i dont use then nothng happens and i can see correct telephone number each time in Parsing classnow this is my detail view classcell.text = aBook.telnumber;earlier i was calling this from sql and that was working cell.text=aBook.tel;now i comment that sql code because now i am calling form xml and now its just null :(
ram
First, I think the cell must be cell.textLabel.text = aBook.telNumber. If that doesn't work, print out aBook and telNumber. And why cell.text=aBook.tel but cell.text = aBook.telnumber. Any diff between telNumber and tel?
vodkhang
About the if, put a breakpoint there to see when it is called, who call it. I think that there is a loop there, or it is get called multiple times. Are you calling it inside the tableView:cellForRowAtIndexPath: ?
vodkhang
A: 

yes i am calling in - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {

switch(indexPath.section)
{

case 2:

pragma mark postcode

        cell.textLabel.text = aBook.telnumber;

             NSLog(@"String = %@",aBook.tel);        
         NSLog(@"String = %@",aBook.telnumber);

}

tel was defined in sql so that was working correct now in xml i hav changes that tel to telnumber thats it and commnet that aBook.tel in sql query nothing else but now its null ... do i need to add xmlparsed elemtns to books in didEndElement in PArsing class??

ram
hey i dont know why i cant click from firfox so i am uisng safari plz write here
ram
plz continue from here i cant open those 25 comments
ram
I think the best practice is openning another question. This section is not built for that
vodkhang
I don't get this part : "do i need to add xmlparsed elemtns to books in didEndElement in PArsing class??" Is the aBook null, and why don't just keep tel just like sql, do you remember to set aBook.telNumber?
vodkhang
ok see this http://stackoverflow.com/questions/3253266/xml-values-are-not-passed-to-detalview-for-iphone
ram
please vote up my answer, at least
vodkhang
offcourse you are the best
ram