June 18, 2008

UIWebView the only class for complex text display on the iPhone

Posted in iPhone development tagged , , , , , at 3:58 am by tetontech

The other day I was exploring the iPhone API looking for a view that would allow me to display text in a complex form like is accomplishable within the UIWebView.  As I did so, I found the UITextView and initially thought I had found the Objective-C analog to what we can do in the UIWebView.  As I read the description in the API documentation I came across this statement.

This class does not support multiple styles for text. The font, color, and text alignment attributes you specify always apply to the entire contents of the text view. To display more complex styling in your application, you need to use a UIWebView object and render your content using HTML.

Now I know one of the reasons that there has been so much interest in how to embed and use UIWebView.  Of course the other is the ability to draw data from multiple web sources easily.
I have enjoyed the ease with which I have been able to accomplish data display using the embedded webkit and have been pleased with its’ speed on the phone considering the limited CPU of a mobile device.
I am now playing with how to get both vertical scroll and horizontal swipe to work in a hybrid application.  The issue is that the UIWebView captures the swipe as a horizontal scroll.  The approach I am taking is to use a transparent view that overlays the UIWebView and then push all of the gesture events either into the UIWebView or into the JavaScript similar to the acceleration events in the example in a previous post.
I’ll let you know the results when I get it working.

Advertisements

8 Comments »

  1. brian said,

    When I load my dashcode project into Xcode using the QuickConnect iPhone hybrid application, I get a white screen. Any ideas on how to fix this?

  2. tetontech said,

    brian,

    I need more information to be able to help you.

    I assume that you replaced the index.html file with a new one and that there are other new files as well.

    If you have not done this already,

    1. Expand ‘Targets’ in your Xcode project
    2. Expand the name of your product as well
    3. Drag each of the new files you have created to the ‘Copy Bundle Resources’ indicator.

    This will cause Xcode to copy your new files from the ‘Resources’ grouping in the Xcode project into the ‘Resources’ directory in your compiled application.

    When I have gotten a white screen this was usually the step that I left out.

  3. tetontech said,

    Bryan,

    The compilation warnings you are getting are telling you that the compiler doesn’t know how to compile javascript files. If you expand your Targets and the application under it you can expand the ‘Compile Sources’ element. You will find each of these javascript files under this element. You should right click on each one and delete it. It will not delete the underlying file. It will remove it from the compilation instruction. These warnings have nothing to do with your white screen problem.

    One item that you will need to handle is that there can be no subdirectories in the Resources directory of the compiled application. The groupings of your code in the project are logical only. If your html file uses sub-directories in the src references for your JavaScript files you will need to flatten the references to remove the sub-directories since Xcode will not create directories to put the JavaScript files in.

    Example:
    src=”Parts/utilities.js”

    needs to be changed in your html file to be
    src=”utilities.js”

    Since each of the HTML DOM elements generated by Dashcode gets filled and modified by JavaScript code, if your html file can’t find your JavaScript files because of the flattening of directories you will get a white screen when you run it in your application.

    We need to get this process documented but with all of the development I have been doing for this architecture in many languages has not left me enough time to do the documentation.

    I hope this helps.

  4. Mike said,

    First, let me say THANK YOU SO MUCH for making QuickConnect… I do not know Objective C, so this has saved me!!

    I have a quick question and you may know the answer to it… beings I do not know Objective C 🙂

    There is a bug with all SDKs (Beta 8 included) that if the phone is rotated to landscape mode and a keyboard is displayed (clicking in a text field, etc), the keyboard is malformed and will crash the app… this isn’t just quickconnect, it’s any UIWebView (even in apple’s sample).

    The quick and dirty fix (until apple fixes it, which could be ages!) is to disabled the accelormeter sensing, or lock the view into portrait.

    Is this possible? If so, how? Ive searched the docs like crazy and cannot find it.

    Thanks!
    mike

  5. Mike said,

    WOOOHOO nevermind! I found it on my own!!!!

    – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    // Return YES for supported orientations.
    return NO;
    }

  6. tetontech said,

    Mike,

    Good job Mike. That is the method that allows or disallows rotation of a view. If anyone else is looking for this you can find it on line 139 of the QuickConnectViewController.m file.

  7. zach said,

    would you be able to create a Post detailing how to pull large amount of content into a UIWebView?

    • tetontech said,

      zach,

      Could you give me a little more information? How much data? What is the source of the data? Is a web service? A web application? Data existent on the Objective-C side? What is the format of the data? JSON? XML?

      Information like this would be of help.

      Lee


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: