Pergunta

Where Do i add my custom tableview cell label in my UITableview when using NSCoder? i already Created The UITableViewCell class and hooked everything up in interface builder.

I tried to replace cell.textLabel.text = oneName.name; with cell.label.text = oneName.name; and it just shows a black square.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (!cell) {
        cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    // Configure the cell...
    NSUInteger row = [indexPath row];
    DrillObject *oneName = [self.addDrill objectAtIndex:row];
    cell.textLabel.text = oneName.name;



    return cell;
}
Foi útil?

Solução

Are you sure your label is of the right size? When using custom cells, I really recommend using the free Sensible TableView framework. The framework automatically loads your objects' data into the custom labels, and will also automatically resize the labels/cells whenever needed.

Outras dicas

There are tow options to add label to your CustomCell class like you want here:
1- add a label onto your cell in xib file and the assign a tag for it and then create a getter like this:

-(UILabel*)label
{
     id label = [self viewByTag:3]; 
     if([label isKindOfClass:[UILabel class]])
     {
             return label;
     }
     return nil;
}

2- create the label in the init method and DONT forget to set the label background color to clear color like this:

UILabel *label = [UILabel alloc] initWithFrame:myFreame];
[label setBackgroundColor:[UIColor clearColor]];

// now you should have property on .h file like this 
@property (nonatomic, weak) UILabel *label;
// so back to the init dont forget to do this

_label = label;

Thats it.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top