warzone_fz
warzone_fz

Reputation: 482

how to configure UITableViewCell in willDisplayCell method?

I am trying to do initial setup of UITableViewCell in will display cell but it does not work. can anyone help me out?

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
     cell.awtxt.font = [UIFont fontWithName:@"Helvetica" size:15.0]; //i am unable to set this .awtxt is the property outlet in my custom ui table view cell named as "postCell"
}

Upvotes: 1

Views: 8487

Answers (2)

user3613932
user3613932

Reputation: 1397

I agree with Mike_NotGuilty. I tried what he suggested for my custom/subclass of UITableViewCell called BNRItemCell with the method definition as follows and it works great:

//This function is where all the magic happens
-(void) tableView:(UITableView *) tableView willDisplayCell:(BNRItemCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Set the cells background color
    if (indexPath.row % 2 == 0) {
        UIColor *altCellColor = [UIColor colorWithWhite:0.3 alpha:0.5];
        cell.backgroundColor = altCellColor;
    }

    [UIView beginAnimations:@"fade" context:nil];
    [UIView setAnimationDuration:20.0];
    [UIView setAnimationRepeatAutoreverses:YES];
    [UIView setAnimationRepeatCount: 0.5];
    [cell.nameLabel setAlpha:0.4];
    [cell.nameLabel setAlpha:1];
    [UIView commitAnimations];
}

You should replace the original method definition with your custom one and try:

-(void) tableView:(UITableView *) tableView willDisplayCell:(PostCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // your code here
}

Upvotes: 3

Mike_NotGuilty
Mike_NotGuilty

Reputation: 2405

For me it worked when I changed the method from UITableViewCell to my custom cell. So just replace the UITableViewCell with your custom postCell

 -(void) tableView:(UITableView *)tableView willDisplayCell:(postTableViewCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath // replace "postTableViewCell" with your cell
 {

  cell.awtxt.font = [UIFont fontWithName:@"Helvetica" size:15.0]; //i am unable to set this .awtxt is the property outlet in my custom ui table view cell named as "postCell"

 }

Upvotes: 5

Related Questions