How do I create a custom UITableViewCell with nib in Xcode 4?
12,627
Solution 1
This blog post describes, how to add it manually.
in iOS4+, the line
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@”CustomCell” owner:self options:nil];
can be replaced by a more efficient nib handling via UINib
.
see this blog post how to do it, and how to stay backwards compatible.
Solution 2
As I understood you already have .h/.m files and you are missing the view (nib).
- Please select new file, select "User Interface" category and empty in sub category.
- Once your nib is created, drag and drop the UITableViewCell on the screen.
- Set the class as First Responder.
Author by
TigerCoding
Tiger Coding provides mobile application consulting and development.
Updated on June 16, 2022Comments
-
TigerCoding almost 2 years
In Xcode 3, I could elect to make a nib when creating a table view cell subclass. In Xcode 4, it only makes the h / m files.
How do I make the subclass with a xib file?
Edit: see screen shots below:
EDIT: Additionally, is there any way to create the UITableViewCell nib automatically, along with the h and m files, all pre-wired and ready to edit?
-
TigerCoding over 12 yearsWhere? When I select: File, New File, Cocoa Touch, Objective-C Class, Next, (type class name), select UITableViewCell from drop down list, Next...it then goes to the create dialog. Nowhere is an option to check with xib for user interface.
-
rohan-patel over 12 yearsNot getting question proprly..can you please explain your question inmore simpler way?So maybe I can help.
-
TigerCoding over 12 yearsStill don't see where or how to create the nib file in XCode 4...
-
Kjuly over 12 yearsHere is a similar question: How to create a UINavigationItem.TitleView based upon a nib file?.
-
Kjuly over 12 yearsCreate xib(nib) file:
File
->New
->New File
->User Interface
->View
. -
Tendulkar over 12 yearsThis link may bel helpful to you.
-
-
TigerCoding over 12 yearsGreat link, but is there a way to not do it manually? Or is that the only way?
-
TigerCoding over 12 yearsClose, but step three is incorrect (see @vikingosegundo link). If I don't have the h / m files, can I make the nib, h and m files all at once somehow (All pre-wired)?
-
vikingosegundo over 12 yearsIt is the only way I ever needed. and a quite elegant one compared to others, that uses xibs without a proper file owner.
-
TigerCoding over 12 yearsAre all the default connections are wired already, such as backgroundView and contentView, or do I need to manually connect them? What about textLabel?
-
vikingosegundo over 12 yearsActually I am not sure, if this connection gets established, as you are not passing in a certain cellStyle. Try it out!
-
TigerCoding over 12 yearsDoing it the way its shown sets it up as a UITableViewCell, so it still keeps its properties. The first link does have an error though, it should be: @property (nonatomic, retain) IBOutlet UITableViewCell *customCell;