How can I make my custom UITableViewCells as fast as possible? - iphone

I'm creating custom UITableViewCells, and I'd like to make them in a way that allows the table view's scrolling to be as smooth as possible. In their current state, with a custom background image on each cell using the cell's backgroundView property, scrolling is is still fairly smooth.
But my question is, how can I add content to the cell and maintain this? The cells are fairly different from each other -- one may have a single label, another may have two labels and an icon, and another may have a bunch of other controls.
I've found that using unique cell identifiers for non-similar rows makes the overall experience laggy, so I need a method that allows me to use the same cell identifier and have very different cells.
Should I be using an XIB for this? If not, how should my subclass function? I was thinking of adding all of the controls to the cell, and only hiding/using the ones necessary at the time. Is there a cleaner way?

Related

iOS Making a custom table view with spaced out and custom cells

I am attempting to make a custom view that looks like the attached picture. The top two cell would be static while the bottom three would scroll if there are more than the screen can fit, and only scroll within that given area. I am wondering what the best approach is to making these types of custom views. I know how to make custom UItableviewcells and have custom content in them, but I am struggling with an overall strategy to make a custom UITableview that has certain cells be static and others scroll. Should I just implement a table view to be part of the screen in storyboards? Or are there better ways to do so?
I would do this by making the top two "cells" just be UILabels, and the bottom a table view where both the cells and the table view would have a clear background. The table view should be set to have no separators between the cells, and the cells should have a UILabel with a background cooler the same as the top UILabels.
This was the result:
I normally do not like to use story board much. And prefer SubClassing UIView. It might take more time to code at first but in a long run it is easier and very dynamic to control the UI programmatically.
In your problem I would make two static UIView(s). If the two view are similar the advantage of using UIView class is that you can use same class with different data model to generate multiple views. But if you use story board you need to copy past multiple times. Hence try to create UIViews class objects as much as possible.
And then the bottom one will be a simple table view. Do not think there is much you can do in this case. Do submit some codes you have done so that we can better refine it.

Subclass UItableViewCell with multiple Legends and Labels

I Know this question has been asked a lot in a hundred different ways (and thats just on this site). But I'm struggling to put all the pieces together.
I would like each UITableViewCell to look like this:
It has multple legends and several fields. The legends are static and wont change but the corressponding labels will vary in width and height. Therefore so will the cells. I need the legends to always align with their labels.
I have tried to do this using the Interface Builder but don't really understand the autoresizing. Though I'm happy to do this in code.
Does anybody know how to do this or at least have some good links to tutorials, source code etc?
Putting a full table view inside a cell is crazytalk. Maybe somebody got it to actually run - that doesn't mean it's best practice or good practice.
I will answer your question after making one very down to earth suggestion. Please consider following Apple's guidelines by putting just a summary of each event in your cells for this table, and allow the user to push down to another view controller to see the details of a particular event. This will probably help you develop your app faster and get to market, then you can think about advanced stuff like customizing individual cell heights at runtime.
That being said, if you insist on putting all your eggs in this basket, then I think you will need to implement your table view cell in IB, note the details for all of your content label frame dimensions, then, at run time, use one of NSString's sizeWithFont:constrainedToSize: methods to determine how big your labels will be. Make them that big. Then from that data compute the height of your cell, and return that value from your table view's tableView:heightForRowAtIndexPath:. This is how I implemented this functionality in an app a few years back. (Frankly I'm not sure that it's still working.) There may be some better methods for figuring out the label size in CoreText, I haven't looked.
A better bet will be to constrain yourself to a limit on the length of text you can put in each label. Then you can just define the labels statically and use a constant-sized cell. Putting it together in IB isn't tough. Just lay everything out, and make sure that you create an IBOutlet and XCode/IB connection for each object you want to manipulate in code.
Good luck!
Add a tableview to each UITableViewCell. The outer tableView will be responsible for holding all your cells and each cell will be a Event with cells for each parameter.
This tutorial will give you insight on how to set that up.
http://iosstuff.wordpress.com/2011/06/29/adding-a-uitableview-inside-a-uitableviewcell/

How To Replicate This User Interface Design?

I want to create a UI like the on in Mint.com app. Is it a UIScrollView with UITableView cells in it?
Notice how each block/cell has multiple data values in it.
This is all about customising the table view and table view cells. The best tutorial I've found is Cocoa with Love: Easy custom UITableView drawing. It's a good place to start.
This is a UITableView with UITableViewStyleGrouped and multiple sections. The spacing between sections appears to be increased from the default value.
The cell backgrounds have a slight gradient added to give them depth. Each section appears to have a different custom layout of labels, and, in the one case, a custom slider-like object. The object on the right is a standard UITableViewCellAccessoryDetailDisclosureButton.
You can achieve similar effects by subclassing UITableViewCell.

UITableViewController custom cell scrolling performance

So I have a UITableViewController. The cells in this tableview have the following UIControls:
2 UILabels, one of which has a shadow and a clearColor background color.
1 Custom Progress view resized to be larger and with a different color
3 UIButtons
Functionally, they do exactly what they are supposed to do. However, I've noticed when looking at it on device that scrolling performance quickly tanks and has dropped frames all over the place, even with other interactions like pushing one of the buttons.
So I was reading around today and found http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/ this article by the Tweetie guy about how to achieve fast scrolling performance by subclassing UITableViewCell and doing the drawing yourself.
The example works extremely well, but when I tried to adapt it to work with my desired configuration I realized that he isn't using any predefined UI Controls, he's mapping out everything by hand.
While I can see how this would be an extremely efficient way to do things, it strikes me as problematic for things like the progress view and the buttons, and even one of my labels to a certain extent.
So my question is this: Do I need to completely write my controls from scratch if I want my scrolling performance to be good, or is there a way to use the standard UI Controls and get good scrolling performance?
If you're adding custom controls to your cell, you should still be subclassing UITableViewCell, adding your controls in the init function, laying them out in layoutSubviews, etc. - just like any other view. As VdesmedT says, make sure you're re-using cells via the dequeue mechanism, so that you aren't allocating new cells with each scrolling operation.
OK, I will propose something obvious but to achieve UIScrollView performance, you need to be sure that the dequeue mechanism works well. I often see developers not properly set the identifier in IB and therefore missing the UITableViewCell cache benefit

Toggling display of image in UITableViewCell

Depending on the result of a condition, I want to display a UIImageView in a table cell. Otherwise display UITableViewCellAccessoryCheckmark. I'd like to construct the cell in IB. The part I'm not sure of what to do with the UIImageView when I don't want it displayed. If I were constructing it all programmatically, I'd add the UIImageView as needed. But since it will be done in IB, the UIImageView is always there. Should the default be leave the cell alone (image displays), otherwise remove UIImageView and display UITableViewCellAccessoryCheckmark? If that is done, will I need a tag on UIImageView so it can be accessed and removed?
You can easily control the visibility of any control, including UIImageView. If you'd like to build things in IB then one solution is to add the controls you need, expose them as properties, and then hide the ones you don't want for a given cell.
E.g.
cell.image.hidden = YES;
When hidden they have no draw-overhead, and although your cell may have thousands of rows there will be very few actual cells, so it's a fairly efficient solution. Just remember that cells are reused if you call [tableView dequeueReusableCellWithIdentifier] (which you should do) so you'll have to explicitly show/hide control whose visibility may have been changed.
An alternative is to have cells with and without images and choose the correct one when adding data to your table. For cells that are similar managing two similar-yet-minorly-different assets would probably be a pain though.