我创建了 UITableViewCell 的子类,在其中设置了单元格的外观/布局。现在我还想通过在单元格层上调用 setCornerRadius 来为单元格添加圆角。我知道我可以在创建单元格时从 tableView:cellForRowAtIndexPath: 设置它,如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
...
[cell.layer setCornerRadius:7.0f];
[cell.layer setMasksToBounds:YES];
}
但是,我想将所有与外观/布局相关的代码保留在子类本身中,所以我的问题是:
在我的 UITableViewCell 子类中的哪个委托(delegate)方法中对单元格层进行更改是合适的?
最佳答案
如果您的单元格是从 Nib 加载的,请将代码添加到 initWithCoder:
方法。如果您使用 -initWithStyle:reuseIdentifier:
创建它在那里添加它。基本上,将其添加到适当的 init
细胞子类的方法。
关于ios - UITableViewCell 子类 : in what delegate method is it appropriate to do changes to the cells layer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17853921/