Fastest method for rendering a table view cell? - objective-c

I'm developing an application that requires me to display many short strings of text in table cells. Currently, I'm using a default table view cell with about 14 UILabels added. Half of these labels contain static text that will not be changed, while the other half contains dynamic data that has to be updated when the table is scrolled.
As my clients are complaining that the table is lagging, I am wondering if there is a more optimized way to display the data, and improve scrolling performance. For example, would the table cells render faster as the table is scrolled if the fixed text is rendered directly onto the view, instead of being contained in UILabels? What other methods can I use to improve scrolling performance?

Performance issues in table view scrolling can be caused by any number of issues. For example:
Make sure the UILabels are opaque to avoid blending. (You can select the color blended layers option in the Core Animation instrument to verify this).
Make sure you're recycling table view cells by using dequeueReusableCellWithIdentifier:
It might be helpful if you could post your implementation of tableView:cellForRowAtIndexPath:

additionally to anshuchimala's answer i would recommend you to remove the static labels and integrate it into a UIImageVie which you use in your tableviewcell as a background image.
Apart from that opacity (as mentioned by anshuchimala) is a big performance-blocker, but also the extensive use ofNSDateFormatter instances can vastly decrease your performance (especially the instantion of NSDateFormatter instances need a lot of power)

Related

Prevent NSOutlineView (or NSTableView) from redrawing on scroll

It seems that my view-based OutlineView try to re-render text every time user scrolling. I think that was because it tried to save memory by re-using rows that fall outside of visible rectangle, then re-render new data to those old views. How can I disable this? I'm willing to sacrifice memory to archive this so that I can get better scrolling performance. (I have tried with various optimize like layer or so, but no luck).
EDIT: There is another question with same purpose as mine here How to make NSTableView not reuse TableCellViews, but no answer yet :(
I think you are confused -- it doesn't re-render the text. The table only shows views for the visible area (caveat below), and pulls in new views as you scroll -- potentially re-using old views.
You provide the view. Use the delegate method viewForTableColumn:row: and return your own cached view for a given row.
But that isn't going to prevent drawing; the view will likely still get marked dirty and draw.
I don't think you are asking the right question. It sounds like you have a performance problem. To help you with that, we'd have to see samples or instrument traces.
Caveat: Responsive Scrolling will pull in views that are in the non visible area. See the AppKit release notes about this.
corbin

How to draw in code an imageview

I have a problem. I want for each record in my core data database to draw an UIImage view on screen. But the problem is that I want to make a sort of grid. On the link below you see what I want to achieve.
picture
So my question is, how do I draw an image on screen in code. And place those images in a sort of a grid. using a collection view is no option, because the app should be running on all IOS devices.
While you could implement a custom UIView and implement the drawRect: method and draw UIImages there, I suggest just using multiple UIImageViews as subviews on your "main" view. Your view might be embedded in a UIScrollView, or you could use a UITableView with custom UITableViewCells. Whichever is easier is probably related to how you can interact with the view.
Building that one huge image view is something that I'd definitely try to avoid - it costs many many (probably unnecessary) memory, and it might be slow as well. Definitely not very flexible to handle, and a pain to update dynamically.
A quick cheat for something like this is to use a Table View and then in each cell to place another TableView but rotated at 90 degrees.
You can then use this second TableView to display the pictures etc...
This will give you a table that scrolls up and down and then each cell can scroll left to right.
I'd suggest subclassing UITableViewCell and setting it up as a UITableViewDelegate and UITableViewDatasource.
You will also have to remember to rotate the content of these "sub"tables by 90 degrees also so that they are the right way up.
This sounds like a lot of work but if you push the management of the sub Tables into the cells then it actually becomes quite easy.

Custom Background Image on Grouped UITableView

How would I go about setting a custom background image for a UITableView. The wrench in the works is that the table is a grouped style (rounded top corners for the first cell and rounded bottom corners for the last cell). I would like do this as much in code as possible without relying on images too much.
Ideally, here is the solution, but I have no idea if this will work or not:
Create one custom background image
Apply the same custom background image to every cell
Rounding occurs automatically because it is a Grouped table style
Profit.
Is this how it works (besides the profit part... I am an app developer, after all)? Do I need to re-think my approach or is this possible? How would do what I described (or another approach) in code specific to iOS 5+?
Update
Just to clarify a bit, the main question I'm asking is: Does the rounding still occur on the top and bottom cells even if you are using a rectangular image?
Well I think what you are saying is ok, but I suggest creating a unique cell layout in a .nib file and apply there the background. Then, with initWithNibName you can manage every cell at the UITableView's methods on the ViewController.

iOS dynamically filling search results

I am building a small Search app on iPad. I want to show the search results. Do I use UIScrollView or UITableView?
The number of search results are unknown & as the user scrolls vertically I'll want to dynamically keep fetching the results & fill whatever container I will be using. Something like what Google Reader (on web) has.
For this purpose which is better suited? UIScrollView or UITableView? Also please guide me as to how dynamically populate the results?
This is an awesome question. I have a different approach for a solution to this problem. It is not the exact answer; But I would assume that the logic might be helpful -
Algorithm:
Decide on a certain number of records being pulled into the UITableView. (lets say 8 ).
You can use a UIScrollView with a small size (rather than setting it with smaller stepping size & frame).
Using the clipsToBounds property (set it to NO), you can actually track the amount of scroll, and check if it goes out of bounds
After you go beyond the bounds, initialize a new UIScrollView with a fresh-list of tables, and get another 8 data entries, and this can be continued.
Reduce the size, set the property and it would work.
But the problem with this is that ; if you try to touch outside the scrolling area => it will not scroll up/down.
Please refer to this tutorial, which can offer some intel on this idea.
And for setting the Scroll amount for Page control => Refer to this question on Stack Overflow.

Cocoa one row table view or a horizontal list view

Is it posible to use table view to show just one row of a big amount of elements? What I'm looking for is for some kind of horizontal list, like we have in XCode preferences or Aperture image list.
It would behave just like a one columnt table view, but instead of showing the elements vertically, it should be horizontally.
Can you point me to where should I start from?
If you're okay with Leopard-only, The new NSCollectionView supports horizontal display. Just set the collection view's number of rows to 1 in Interface Builder; it'll even handle the horizontal scroll bar for you. The IconCollection sample code provides a simple demonstration of how it works. It's bindings work similarly to a table view's, except instead of rows and columns, each object represented gets an 'item' (an object of type NSCollectionViewItem) that displays it, and those items will be laid out in a grid. The sample code above demonstrates how to set up these 'items' in Interface Builder, which is definitely the easiest way.
With a table view? No. If I'm understanding correctly what you want, in the past I've created my own NSView subclass for this type of control. Define a data source protocol similar to NSTableView, and in your NSView drawRect method, draw the elements in order one by one from left to right. You can either keep track of paging in your control, or put it in a scroll view and resize yourself whenever the number of items changes.
Usually this type of thing starts off pretty simple, and gets a bit complex once you start handling caching, paging, selection, mouse and keyboard input and so on. My advice, start as simple as possible and add new features one by one, only after you've finished the previous task.