Search code examples
iphoneobjective-ciosuiwebviewuitextview

Fill in the blanks model


I've been trying to figure out the correct model for this new app of mine. Here's the thing. I need to create an exam type app. The app will have a "Grammar" section which requires a paragraph with fill in the blanks approach. So it will look like this.

    "Lorem ipsum dolor sit amet, _________________ , sed do eiusmod tempor 
     _______ ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud 
     exercitation ullamco _________________ ex ea commodo consequat. Duis aute 
     irure dolor in reprehenderit in voluptate velit esse _______ dolore eu fugiat nulla 
     pariatur. ____________ sint occaecat cupidatat non proident, sunt in culpa qui   
     officia deserunt mollit anim id est laborum."

Now, the paragraph is coming from the server. We mark the blanks as {#} so when I display it on the app I will replace it with "____" w/c is equivalent to a uitextfield. The problem is I've no idea how to go about this. Can I put everything in a uitextview? how should I deal with the blanks? And I dont think I can do this with uiwebview coz I need the update the contents of the blanks once I tap on them. Please help.


Solution

  • You can use UIWebView. And for updating the contents of the blanks you can write javascript inside the HTML pages and bind it with onselect event of the blanks.

    You can have a look at my answer iOS UIWebView Javascript - insert data -receive callbacks?

    to know more about communicating with a webview. (i.e. executing javascript from Objective C and vice versa)


    Update for the comment

    Yes, you can pass a string to the webview from outside ,

    [webViewInstance stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"displayTheStringInBlank(%@)", stringValue]];
    

    and write a JS function is your HTML file to get and display the string in the blank,

    function displayTheStringInBlank(stringValue)
    {
    //Write code to use the string in the blank
    document.getElementById("yourInputIdElement").value = stringValue;
    
    }