views:

32

answers:

1

I have implemented a custom table view cell. I can get the cell to load, that is not the issue. What I am struggling with is setting the text property of the label. My code is below, what am I doing wrong?

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    [self.icaoLabel setTag: 1];
    [self.nameLabel setTag: 2];
    [self.tafLabel setTag: 3];
    [self.metarLabel setTag: 4];

    static NSString *CellIdentifier = @"customCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed: @"TAFandMETARCustomCell" owner: self options: nil];
        cell = customCell;
        self.customCell = nil;
    }

    // Configure the cell...
    TAFandMETAR *taf = (TAFandMETAR *)[tafAndMETARs objectAtIndex: indexPath.row];

    //cell.textLabel.text = [dateFormatter stringFromDate: [taf creationDate]];
    UILabel *label;

    label = (UILabel *)[cell viewWithTag: 1];
    label.text = [taf icaoCode];

    label = (UILabel *)[cell viewWithTag: 2];
    label.text = [taf airfieldName];

    label = (UILabel *)[cell viewWithTag: 3];                   
    label.text = [taf taf];

    label = (UILabel *)[cell viewWithTag: 4];                   
    label.text = [taf metar];

    return cell;
}

Thanks.

+1  A: 

Assuming that your labels are subviews of your custom cell and are present in cell's nib file then the easiest way to set tags for them is to do that in IB directly - choose each label in IB and set its tag in inspector window.

Vladimir
Thanks - I didn't spot the Tag option earlier. The next problem then - it only displays the data when you select the cell - otherwise it is blank. Also, the original label text (so I can identify each label on the nib) just gets written on top of, so there are 2 different lots of text. WHat have I done wrong?
churchill614
I'm not sure what I did wrong, but recreating the cell in IB has fixed the issue.
churchill614