I am new to iphone development. I am using xCode 4.2 with storyboard. I am trying to get cells in my tableview to display several uilabels. They just aren’t appearing in my simulator. but the original cell.textLabel is appearing.
here’s what I did:
I created a new customcell.h/.m files that extend the UITableViewCell. I added some instance variables in the class. I went to the storyboard and in the class of the identity inspector of the tableviewcell, i changed it to point to customcell. I dragged and dropped some UIlabels into my new cell. I then went to the connection inspector to drag those “plus” icons with lines to connect to my new uilabels to my instance variables.
When I run my simulator, I don’t see any of my new ui labels. I only see the original uilabel of cell.textLabel. I can programmatically get and set cell.mylabel1, cell.mylabel2 etc…, which are new labels, but hey just are not appearing.
Additioanl Details
This i the cellForRowAtIndexpath function for my tableviewcontroller.
static NSString *CellIdentifier = @"Cell"; // this was the error, i needed to change this to CustomCell, or whatever it is in my storyboard
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.mylabel1.text = @"hello"; // doesn't appear in simulator
cell.textLabel.text = @"world"; // does apepar in the simulator
As David has alluded, the one missing piece here is that you need to reference the Identifier of the cell specified in the Storyboard:
First, specify an identifier in the “Attributes Inspector” in the storyboard. You can do this by selecting the UITableViewCell and adding an identifier “ExampleCell” (for example). Second, reference this identifier in the code when creating the CustomCell.