ios - UITableViewCell 子类 : in what delegate method is it appropriate to do changes to the cells layer?

标签 ios objective-c uitableview

我创建了 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/

相关文章:

ios - 如果 navigationBar.translucent 为 NO,则 UITableView 底部区域保持在屏幕之外;

iOS 定期后台位置更新,这不仅取决于重大的位置变化

objective-c - 如何托管 Apple 的 Pitch Shift Audio Unit 插件等

objective-c - 为什么 cocoa 绑定(bind)不能与框架类的 typedef 一起使用

ios - 滚动过去 UITableViewCell 查看新内容

ios - 如何使用标识符将 NSLayoutConstraint 访问到 tableviewcell 中?

iphone - 将自定义 UI 对象 (UISwitch) 添加到 iOS 项目

iOS 7 状态栏重叠内容

ios - 如何在我的应用程序中实现 UITapGestureRecognizer

iphone - 暂时阻止 UITableViewCell 被回收