views:

42

answers:

2

Hi, i did a text rendering program using UIView and UITableViewController. What i did is before going drawRect method, i just calculate all of the cells height as well as each text start & height,width. So that, i can estimate the cell height approximately and then i draw the text.

I did this for both portrait & landscape mode. My program looks like twitter updates. When the user changed to landscape mode i calculated the same things for landscape mode. Next time, i simply retrieve the stored data for drawing text(Valid before application quits).

Now my problem is, when my inputs are less, it works good. But for the huge input say 100 inputs, it takes some time to show the text. Also, my program's scrolling is somewhat not smooth. Also there is no leak in my application.

Please anyone suggest me the good way to do this application and make it so smooth and faster...

Thanks in Advance, Rajkanth

+1  A: 

The short answer to this is to minimize any computation you do in rendering of the cells. This includes any transparent backgrounds. To achieve the fastest scrolling, ideally you would have very few amounts of non-opaque elements.

coneybeare
Thanks for your reply. You said to reduce the computational factors of the cell. How is it possible? I need to do character wrapping, word wrapping, calculation of height of each cell before display it etc. I used opaque value as 1. Need to do so many string calculation to display a paragraph. Then what should i do?
Rajkanth
There are many ways to do this, but the best way is to figure out all content before the rendering of the cells. This way, when the cells are rendered, it is a simple memory lookup for the values.
coneybeare
The way I achieve it (amongst other things) is through three20. In three20, you setup an object called a tableItem before rendering the cells. Typically, all items would be setup and stored. Then when it is time to scroll, the cells know which methods to call on the precomputed items to pull the info fast without computation. The items are usually rendered in the loading of the view, during the navigation transition.
coneybeare
Thanks for your reply.. I did the same procedure without three20. I just calculate each words details and stored in an array. Then only im drawing text and images using that stored values. I'm calculating all strings details like height, width, position etc at a same time. It takes so much time. Is it possible to calculate only for visible portion of the table and doing background calculation and storing for other cells? that is i simply calculate details for some cells then display them, then calculate for non-visible cells and stored in the array. Is it possible?
Rajkanth
+1  A: 

The trick is to only have one big opaque element by coalescing all your individual elements into a single view.

http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/

kubi