TableView不会输入willDisplayCell

Jak*_*kub 1 iphone objective-c tableview ios

我的目标是定义我自己的单元格样式,背景,字体和大小.我试试这个.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ScreenListElements *currentScreenElement = [self.screenDefBuild.elementsToTableView objectAtIndex:indexPath.row];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:currentScreenElement.objectName];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:currentScreenElement.objectName];

    }

    cell.textLabel.text = currentScreenElement.objectName;

    return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{  
cell.contentView.backgroundColor = [UIColor blackColor];
}
Run Code Online (Sandbox Code Playgroud)

我想更改单元格背景,但我的应用程序不会进入willDisplayCell方法.我宣布我的班级为:

@interface MyTableView : UIViewController  <UITableViewDataSource,NSCopying> {
}
Run Code Online (Sandbox Code Playgroud)

我还有别的吗?或许是一种更好的方式来声明自己的细胞风格.

hp *_*der 6

@interface MyTableView : UIViewController  <UITableViewDataSource, UITableViewDelegate ,NSCopying> {
}
Run Code Online (Sandbox Code Playgroud)

方法

tableView:willDisplayCell:forRowAtIndexPath
Run Code Online (Sandbox Code Playgroud)

是委托方法 UITableView

编辑(使其正确和接受的答案)

设置代表

[myTableView setDelegate:self];
Run Code Online (Sandbox Code Playgroud)