What are your favourite UITableView / UITableViewCell tricks? [closed] - iphone

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
UITableView is a very powerful class, powering many navigation and preference views on iPhone. Many people have come up with useful UITableView tips, tricks and samples:
various ways to use Interface Builder for table cells
how to create preference-style cells
ensuring good scrolling speed
etc.
Please post your favourite tips on using UITableView, one tip per question. I'll start by posting the ones I found on Stack Overflow and the ones from my bookmarks.

Ever wondered what UITableViewController really does?
In viewWillAppear, it deselects any selected rows, with animated:YES.
This by the way is why when you navigate back in UINavigationController, the row you've previously touched is nicely deselected with animation. When you pushed a new view controller onto UINavigationController, you've left the row selected. When you pop it and go back to the table view, viewWillAppear fires and deselects the row. UINavigationController does not even know about this happening.
In viewWillAppear, it calls reloadData if the table view contains no rows.
In viewDidAppear, it calls flashScrollIndicators.
It monitors the keyboard appearing and disappearing and resizes the table view appropriately so that when you tap a text field in a table view, it remains visible after the keyboard appears.
If you don't need the keyboard monitoring behaviour, it is fairly easy to do everything else yourself if you need to.

Implementing “checkmarks” in editing mode to manipulate several rows at once: “Multiple row selection and editing in a UITableView” from the great Cocoa With Love blog.

How to implement a custom cell background view?
An excellent sample class by Mike Akers in “How to customize the background/border colors of a grouped table view?” on Stack Overflow.

If you want to remove the separator lines, use this:
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

To ensure good performance scrolling, it's important to avoid transparency in any element if possible - so if you are creating custom cells make them all opaque and set the backgrounds correctly.
You can use the Core Animation Performance Tool to visually see how much transparency you have going on in a cell - you have to be running on the device to use this tool.

Implementing Preferences-style grouped tables: Three20 library (extracted from Facebook iPhone app) has a set of ready-made cells that contain various controls.
(Not sure you want to use them, however. Three20 suffers from “not-invented-here” a little bit and tries to subclass and extend everything, so adding it adds quite a bit of a mess to your project. But at least you can use it as an example.)

How to use Interface Builder to author your cells? Find answers on a separate Stack Overflow discussion: “Using Interface Builder for UITableView’s”

Related

Calling reload data while scrolling on UIScrollView

I am implementing a UIScrollView which behaves mostly like a UITableView, a bit more advanced with that.. but most of the API used are the same signature.. cellForRowAtIndexPath.. etc. First before people start storming why not just use a UITableView, let me just say that I can't. The reasons are fairly complex, but that is a decision been made.
The issue is now I am implementing infinite scrolling, basically when I scroll down and I am at 65% of the full contentHeight I am doing an async request to the backend to fetch more data and adding it to the data source and then calling reloadData. The issue is that if I am calling reloadData while the user is scrolling, it doesn't provide a very smooth scrolling experience. So what is the best way to tackle this? Also I noticed that reloadData basically refreshes the entire table view (in this case my scroll view). In my table view cell I am animating a UIImage to fade in. So when reloadData is called, the image that is already presented is being faded in again, which is kind of annoying.
How do I avoid such things?
Any tips and tricks?
In case you're still working on this, check out PSTCollectionView. It works exactly like UICollection view but supports backwards of iOS 4.3.
Its difficult to answer without knowing why you need to create a custom view similar to the tableview. If you have a developer account you might want to check the new iOS 6 view based on tableview. Not sure if I can talk more about it as it is under NDA.
For the UIImage fading, how about flagging each UIImage as displayed and then do a check when reloading the data or recalling the fade statement. Only fade the images that are not flagged as already presented?
In new iOS 6.0 there is new controllers call UIContainer view,its similar to UITableview but we can also set more then one column with that.
delegate methods for that controllers are almost same as in UITableview.you can use that controller if you have similar requirements.

Custom tab bars, table views, etc

this is my first question here at Stack Overflow.
I've been looking for a way to do this ever since I started programming for iOS (which was really not that long ago, about a month) but I haven't been able to find any concrete explanation, so I decided to ask you.
I've seen many apps that have custom artwork in them (e.g. wooden textures, backgrounds with noise, custom table view cells, etc.) and I would like to add some to my own apps, are there any properties that I can access, say for example, on a tab bar?
Check out Wunderlist or ReadMore, these two are great examples of what I mean.
Wunderlist was made using Titanium, obviously editing backgrounds and customizing table view cells and table view backgrounds is easier in JavaScript, but if Titanium has a way of doing it then there must be a way of doing it natively in Objective-C, right?
Thank you in advance, your help is very much appreciated.
There are a number of ways to create a custom UITableView and associated cells.
As a general overview, the Cocoa with Love Easy custom UITableView drawing blog post is pretty good and there's also a more recent (and complex) UITableView construction, drawing and management (revisited) post on the same site if you really want to go for it on the customisation front.
there a few ways of customizing UITabelViewCells.
Table View Programming Guide for iOS
Interessting Chapters:
Programmatically Adding Subviews to a Cell’s Content View
Loading Custom Table-View Cells From Nib Files
Subclassing UITableViewCell

How can I create my own UITabBar? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Further to this question here, I'm really interested in creating my own UITabBar, and 'rolling my own'. Im really curious as to how this is done, especially in an app such as the Twitter app.
How can I do this? Can anyone point to any good resources on how to subclass this?
Should I do it programmatically, or in a XIB?
Edit: I'm looking to do this with custom icons/selected icons and having icons only.
Edit2: After reading further answers, it sounds like a custom XXTabBarcontroller is what I actually want to do here. Can anyone comment on this?
Thank you,
I don't know if there is a best way to do this, but I will share my experience:
I created my own version of a tab bar by subclassing UIView as opposed to UITabBar. As the linked question mentions, Apple's UI classes are quite finicky about their sizing and I do not think I could get the UITabBar subclass to size as I wanted.
Because I did not have a subclass of UITabBar I also ended up rolling my own versions of UITabBarController and UITabBarDelegate, with interfaces that are essentially the same as the Apple classes. I WAS able to use UITabBarItem to store the title and icon for the buttons on the tab bar, which is useful since UIViewControllers have a tabBarItem property. That lets you store just an array of UIViewControllers in your controller, as opposed to arrays for both controllers and tab bar items.
Because I was using mostly custom classes I did this all programmatically, including creating, configuring and laying out the buttons on the tab bar.
Like I said, this is just my experience, hope it helps.
I did this recently in an application. There was so little "code" to it that there is barely anything to post. I did it as such:
Created a UIImageView (about 50 px high), and laid it out at the bottom of the screen. I filled it with a tab-bar look-alike image - i.e. some sort of grey gradient. I probably subclassed UIImageView - but you don't even have to do that.
I drew a bunch of buttons/icons - 37x37 each.
I placed a bunch of UIButtons in the "tab bar" - and made them "Custom" views, with the buttons/icons I had created.
I simply used the touchUpInside methods to make them do stuff.
When I needed to get fancy - I'd attach the buttons to my code via and IBOutlet, so I could "disable" them - and I'd draw a greyish "disabled state" image for them.
If you want the same functionality, I'd recommend using a UITabBarController, hide the tab bar itself, and then create your own navigation. I've done this a few times and it works quite nicely.
Use something like this to hide your tab bar and expand the content view.
- (void)makeTabBarHidden:(BOOL)hide
{
if ( [tabBarController_.view.subviews count] < 2 )
return;
UIView *contentView;
if ( [[tabBarController_.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
contentView = [tabBarController_.view.subviews objectAtIndex:1];
else
contentView = [tabBarController_.view.subviews objectAtIndex:0];
if (hide)
{
contentView.frame = tabBarController_.view.bounds;
}
else
{
contentView.frame = CGRectMake(tabBarController_.view.bounds.origin.x,
tabBarController_.view.bounds.origin.y,
tabBarController_.view.bounds.size.width,
tabBarController_.view.bounds.size.height - tabBarController_.tabBar.frame.size.height);
}
tabBarController_.tabBar.hidden = hide;
}
Then make your own navigation with UIButtons to switch between your view controllers.
[tabBarController_ setSelectedIndex:0];
I think this is what you are looking for... should be pretty easy to subclass it. gl and cheer!
http://www.rumexit.co.uk/2010/07/how-to-customise-the-tab-bar-uitabbar-in-an-iphone-application-part-1-of-2/

Does apple mind you using that striped table view background in your own views?

The ones they use with grouped table view.
I'm using a table view that links to another view that has text on it. To make it look less 'plain' I wanted to add that striped background and then put something like a white 'text box' on that.
Do they allow it to be used?
Yes, they do allow that. I've done so in an application that has been updated and re-approved several times over. The pattern is available as [UIColor groupTableViewBackgroundColor].
sure.
For more details you may want to look at Apple's Human Interface Guidelines.
No, they don't mind. Why would they?
It shouldn't be a problem.
If you start doing something more complicated than a text box, say a button that you click that slides in another view controller, you're going to be duplicating a lot of UITableView/UITableViewController code, and you're better off just creating a UITableView with a controller and couple of singleton UITableViewCells in your nib file.

What is the method to delete the custom cell from UITableView? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
i have a custom cell i want to delete it when a button is clicked situated on the custom cell itself.how do i achieve this. someone help i am stuck at this from many days
Not sure why you want to do this instead of using the standard delete behavior, but...
First you need to know the indexPath for the cell on which that button is being pressed. So you have to wire the custom cell to receive the button action, and then call the table's indexPathForCell method with that cell to get the indexPath.
Once you have it, you put the indexPath inside an NSArray and pass it to the table's deleteRowsAtIndexPaths method (and also choose the type of animation for removing the cell). This will also invoke the dataSource's commitEditingStyle method to let you delete the underlying data as well.
Keep in mind that by doing it this way, you're bypassing the two-step delete process that is built into the table -- where the user would normally request a delete and then have to confirm it. So for the sake of safety, you'll probably want to implement something like that yourself.
Also, the default behavior for swiping across a table cell is to bring up the delete button. You may want to override the editingStyleForRowAtIndexPath delegate method and return UITableViewCellEditingStyleNone for that cell so it doesn't do the default thing.