I have been playing around with tableviews for the past few days trying to get used to them, today I have been trying to create a custom uitableviewcell, I am working from the Table View Programming Guide in the apple documents and have this weird problem with something I am trying to do.
I have set up a custom cell nib file, it has two labels on it that both have tags (0 and 1) I have changed the File owners class to the nib that will be using it.
from there I have started programming the tableView:cellForRowAtIndexPath: method that displays my custom cells inside the tableview however as you will see, only my first label is showing when I assign it a string and I just don’t know why…
Custom cell Nib

tableView:cellForRowAtIndexPath: method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
//cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
[[NSBundle mainBundle] loadNibNamed:@"ManufactureSearchCell" owner:self options:nil];
cell = vehicleSearchCell;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
self.vehicleSearchCell = nil;
}
// Configure the cell...
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if(indexPath.section == 0)
{
if(indexPath.row == 0)
{
UILabel *label;
label = (UILabel *)[cell viewWithTag:0];
label.text = [[NSString alloc] initWithString:@"Manufacture :"];
label = (UILabel *)[cell viewWithTag:1];
label.text = [[NSString alloc] initWithString:@"empty"];
}
else if(indexPath.row == 1)
{
//.....
Any help would be appreciated 🙂
Beware using viewWithTag and 0. That is the default tag for all views, so double check you are actually getting the label you want back from that instead of the cell’s background view, or accessory view, or any other default view added to the cell. It can cause problems.
If you are reusing the cell, I’d recommend creating a custom UITableViewCell subclass and link them through IB. If you are not reusing that cell, and want it to display only once, definitely take up Karoly’s suggestion to just have those labels as IBOutlets.