ios - 覆盖从 xib 文件初始化的 UITableViewCell

标签 ios

我想在初始化我的自定义 UITableViewCell(来自 xib 文件)时动态地​​更改一些东西(隐藏 UITextView,更改字体颜色),但不调用 initWithStyle 选择器。

我的代码如下:

目标表单元格.h

@interface GoalTableCell : UITableViewCell

  @property (strong, nonatomic) IBOutlet UILabel *fixedText;

  @property (strong, nonatomic) IBOutlet UITextView *editableText;

  @property (strong, nonatomic) IBOutlet UIImageView *imageCircle;

@end

目标表单元格.m
@implementation GoalTableCell

- (void) setup
{
  self.editableText.hidden = TRUE;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
  if( self = [super initWithStyle:style reuseIdentifier:reuseIdentifier] ) {
    [self setup];
  }

  return self;
}

@end

最佳答案

当从 NIB 文件中取消归档任何实例时,'initWithCoder: method will be called because the archived properties are provided to the instance via the解码器参数。

从 NIB 加载实例时,awakeFromNib方法也被调用。

initWithCoder: is called to create the instance. awakeFromNib` 在实例从 NIB 完全取消归档(连接导出)后被调用。

关于ios - 覆盖从 xib 文件初始化的 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17664888/

相关文章:

ios - RestKit 和 Cocoapods : Mapping operation failed/did not find any mappable values

ios - 在 F# 和 Xamarin 中将元组转换为数组

ios - ipad 3 - kEAGLDrawablePropertyRetainedBacking 和视网膜的 openGL 错误?

ios - iOS Objective-C使所有“打开方式”中都出现一个应用程序

iOS 8 Mapkit 和位置 - 每天的请求数量有限制吗?

ios - dyld : Library not loaded: @rpath/MapboxMobileEvents. 框架/MapboxMobileEvents

ios - 使用iOS CIDetector人脸检测触发功能

ios - CSS 动画在 iPhone/iOS12.2 上不起作用

ios - 像照片应用一样模糊UINavigationBar

java - MonoTouch + IKVM 项目中的 JIT 编译问题