我正在尝试初始设置UITableViewCell
将显示单元格,但它不起作用。谁能帮助我?
-(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"
}
答案 0 :(得分:5)
对我而言,当我将方法从UITableViewCell
更改为我的自定义单元格时,它才有用。
因此,只需将UITableViewCell
替换为您的自定义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"
}
答案 1 :(得分:3)
我同意Mike_NotGuilty。我尝试了他建议的UITableViewCell的自定义/子类,称为BNRItemCell,方法定义如下,并且效果很好:
//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];
}
您应该使用自定义方法替换原始方法定义,然后尝试:
-(void) tableView:(UITableView *) tableView willDisplayCell:(PostCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// your code here
}