Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableViewCell子类:在什么委托方法中对单元格层进行更改是合适的?_Ios_Objective C_Uitableview - Fatal编程技术网

Ios UITableViewCell子类:在什么委托方法中对单元格层进行更改是合适的?

Ios UITableViewCell子类:在什么委托方法中对单元格层进行更改是合适的?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我已经创建了UITableViewCell的子类,在其中设置了单元格的外观/布局。现在,我还想通过调用cells层上的setCornerRadius来为单元格添加圆角。我知道我可以在创建单元格时从tableView:cellForRowAtIndexPath:进行设置,如下所示: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

我已经创建了UITableViewCell的子类,在其中设置了单元格的外观/布局。现在,我还想通过调用cells层上的setCornerRadius来为单元格添加圆角。我知道我可以在创建单元格时从tableView:cellForRowAtIndexPath:进行设置,如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];

    ...

    [cell.layer setCornerRadius:7.0f];
    [cell.layer setMasksToBounds:YES];
}
但是,我希望将所有与外观/布局相关的代码都保存在子类本身中,因此我的问题是:


在my UITableViewCell子类中的哪个委托方法中,可以对单元格层进行更改?

如果您的单元格是从nib加载的,请将代码添加到
initWithCoder:
方法中。如果您使用
-initWithStyle:reuseIdentifier:
创建它,请将其添加到那里。基本上,将其添加到单元格子类的相应
init
方法中。

如果您的单元格是从nib加载的,请将代码添加到
initWithCoder:
方法中。如果您使用
-initWithStyle:reuseIdentifier:
创建它,请将其添加到那里。基本上,将它添加到你的cell子类的相应的
init
方法中。

为什么不在MyCell.m in-init或smth中设置“cornerRadius”这样的值?为什么不在MyCell.m in-init或smth中设置“cornerRadius”这样的值?哦,伙计,当我实际上从nib文件加载它时,我没有意识到我在initWithStyle中设置了角半径-这就是为什么我认为我必须在某种秘密委托方法或其他方法中设置它。你的回答让我意识到了我的错误(现在我觉得有点愚蠢:S)。谢谢哦,伙计,当我实际上从nib文件加载它时,我没有意识到我在initWithStyle内设置了角半径-这就是为什么我认为我必须在某种秘密委托方法或其他方法中设置它。你的回答让我意识到了我的错误(现在我觉得有点愚蠢:S)。谢谢