Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading a Reusable UITableViewCell from a Nib

I am able to design custom UITableViewCells and load them just fine using the technique described in the thread found at http://forums.macrumors.com/showthread.php?t=545061. However, using that method no longer allows you to init the cell with a reuseIdentifier which means you have to create whole new instances of each cell at every call. Has anyone figured out a good way to still cache particular cell types for reuses, but still be able to design them in Interface Builder?

like image 452
Greg Martin Avatar asked Jan 05 '09 18:01

Greg Martin


2 Answers

Actually, since you are building the cell in Interface Builder, just set the reuse identifier there:

IB_reuse_identifier

Or if you are running Xcode 4, check the Attributes inspector tab:

enter image description here

(Edit: After your XIB is generated by XCode, it contains an empty UIView, but we need a UITableViewCell; so you have to manually remove the UIView and insert a Table View Cell. Of course, IB will not show any UITableViewCell parameters for a UIView.)

like image 85
Tim Keating Avatar answered Oct 05 '22 02:10

Tim Keating


Just implement a method with the appropriate method signature:

- (NSString *) reuseIdentifier {   return @"myIdentifier"; } 
like image 32
Louis Gerbarg Avatar answered Oct 05 '22 02:10

Louis Gerbarg