views:

85

answers:

1

I'm new to iPhone development, and I have a question on how to create a view for my application.

The view should display a problem (using formatted/syntax highlighted text), and multiple possible answers. The user should be able to click on an answer to validate it.

Currently, I am trying to use a UITableView embedding UIWebView as contentView. That allows me to display formatted text easily. The problem is that it is a real pain to compute and adjust the height of the cells. I have to preload the webview, call sizeToFit, get its height, and update the cell accordingly. This process should be done for the problem and the answers (as they are HTML formatted text too).

It's such a pain that I am planning to switch to something else. I thought using only a big UIWebView and design everything in HTML. But I looked at some articles describing how to communicate between the HTML page and the ObjectiveC code. This seems to involve some awful tricks too...

So... that's it, I don't really know what I should do. I guess some of you dealt with such things before, and would provide some greatly appreciated tips :)

+1  A: 

The catch here is that the iPhone API does not yet support NSAttributedString so you can't just set the text to appear as you would like in a textview.

I saw one work around which essentially used individual UILabels to represent each attribute run. (Can't find the link now.) They used NSString UIKit extensions to calculate the position of the strings on the view and then used that to position the labels.

Another work around would be to draw the strings with their attributes to a UIImage and then just display the image. That would be the easiest solution I think.

In either case your going to have to basically recreate the data structure of an attributed string.

NSAttributedString does a lot of work for us. We really miss it when it is gone.

TechZen
The problem when using labels and strings, is that I would need a markup language to decorate them. Currently the problems and answers are stored as HTML text in a database. I don't know any other way than HTML to store decorated text.
Aurélien Vallée
Well, seems there won't be any other answer here :) Thanks for your time !
Aurélien Vallée