-(NSMutableArray *)titlesFromString:(NSString *) pageData
{
NSMutableArray *foundTitles=[[NSMutableArray alloc] init];
NSScanner *scaningPage = [NSScanner scannerWithString:pageData];
NSString *title;
for (int i =0;i<4;i++) {
[scaningPage scanUpToString:@"class='topic_title" intoString:NULL];
[scaningPage scanUpToString:@">" intoString:NULL];
scaningPage.scanLocation++;
[scaningPage scanUpToString:@"</a></h4>" intoString:&title];
[foundTitles addObject:title];
}
status.text = [[NSNumber numberWithInt:[foundTitles count]] stringValue];
for (NSString *titlesLife in foundTitles){
[results.text stringByAppendingString:@"\n"];
[results.text stringByAppendingString:titlesLife];
}
return(nil);
}
right now i'm returning nil until get it working. I'm calling this method from connectionDidFinishLoading.
in the documentation they use a while loop while ([theScanner isAtEnd] == NO){} but they are also doing this on a regular data set, where the last thing scanned is at the end of the string so i'm guessing that's why i'm running into a bounds issue. i've also seen the RegexKit Framework and that may work better than the parser. until i get the while loop figured out i have a for loop just getting some of the info. I'm thinking i'll need to check for the existence of another element and if not then scan for in order to not have the scanner go out of bounds.
i'm also confused why i need to increment the scanner location once scanning the '>' into null other wise i end up with strings like "> What Song is On Right Now???" i'm also using a NSURLConnection to get the data when i think it may be simpler to use initWithContentsOfUrl but it's nice getting experience with the connection route.
the second chunk is me trying to add my results to the results UITextView which doesn't seem to be working. i shouldn't have to setNeedsDisplay should i? i thought that was only when drawing the view in code. Thanks for any suggestions.