25 Apr 2013, 06:57
Avatar_2_pragsmall

Eliezer Talón (1 post)

Hi,

Recipe 15 tells us a way to simplify cell production. When adding subclasses of a UITableViewCell foundational subclass, let’s say PRPSmartTableViewCell:, how should the custom initializer be overriden? I normally write my initializers this way:

- (id)init {
  self = [super init];
  if (self == nil) {
    return nil;
  }

  // custom stuff
  return self;
}

But when overriding @initWithCellIdentifier:@ I’m not sure if a message to @super@ must be assigned to @self@ or to a local variable:

- (id)initWithCellIdentifier:(NSString *)cellID {
  PRPSettingsTableViewCell *cell = [super initWithCellIdentifier:cellID];
  if (cell == nil) {
    return nil;
  }

  // custom stuff
  return cell;
}

vs.

- (id)initWithCellIdentifier:(NSString *)cellID {
  self = [super initWithCellIdentifier:cellID];
  if (self == nil) {
    return nil;
  }

  // custom stuff
  return self;
}

Does it make any difference? Which are the cell reuse mechanism implications here?

Thanks!

  You must be logged in to comment