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 09-26-2011, 02:18 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2011
Location: Tokyo
Posts: 1
pietrozuco is on a distinguished road
Default iOS Using HTML links to fetch data

I'm creating an interactive book for learning languages. It has reading, quiz and some simple game. The content of each chapter is an HTML file. The book allows the user to learn about 300 words that exist in the text. Earch word was enclosed in a link like this: < a href="word">word< /a> when the user touch the link, a modal view appears with the translation and information about that word.

This is the code I'm using to get the link:

Code:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{   
    // currentWord is the word in the link
    self.currentWord = [[request URL] lastPathComponent];

    // okToCatchLinks is a BOOL that I use to avoid showing the modalview when the page
    // is loaded for the first time.
    if (okToCatchLinks){
        NSLog(@"Ok to catch links!");
        WordViewController *viewController = [[WordViewController alloc] initWithNibName:@"WordViewController" bundle:nil]

        // I did my homework creating the delegate protocol to dismiss the modal view.    
        viewController.delegate = self;

        // This is a label in the modalview showing the word in the HTML link.
        viewController.labelTitle = self.currentWord;

        // Create a Navigation controller to add the "DONE" dismiss button
        UINavigationController *navController = [[UINavigationController alloc]
                                             initWithRootViewController:viewController];
        navController.modalPresentationStyle = UIModalPresentationFormSheet;
        navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

        // show the navigation controller modally
        [self presentModalViewController:navController animated:YES];

        // Clean up resources
        [navController release];
        [viewController release];
    }
    okToCatchLinks = YES;
    return YES;
}

With this code I will get the selected word in a string variable. Then I search that word in the DB using CoreData. The HTML is UTF-8 encoded. I have to be able to search for that word in different languages. So if the user click on the word (日本語) or (résumé) I have to be able to find it in the DB. For the data store I converted an CSV file to a .sqlite file.

I wonder if there is a better way to do this. Personally I don't like to use < a href=""> to get the link, but I couldn't find any other way to get the current word in a link. Also performing the search of that word in the DB is not clean, because I'm not using any UID for each row. I just compare the string holding the word with the words in the corresponding column of the DB.

Is there a more efficient way to do this?

To resume: Having a list of words, mark those words in the HTML so the user can touch and retrieve information about that word from a DB.

Thank you in advance.

Pietro
pietrozuco is offline   Reply With Quote
Reply

Bookmarks

Tags
core data, uiwebv

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: 394
15 members and 379 guests
13dario13, 7twenty7, eski, EvilElf, glenn_sayers, HemiMG, iOS.Lover, jarv, n00b, pbart, Pudding, sacha1996, Sami Gh, UMAD, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,905
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

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