How to get multiple copies of a UIView loaded from a tip?

I want to use the UIView hierarchy several times (the nib object is a template). Unfortunately, UIView does not match <NSCopying>, so

[cell.contentView addSubview: [[templEditCellView copy] autorelease]];

does not work.

I was not surprised, as I need a deep copy of the hierarchy of views.

Presentation is one of several top-level objects in a loadable nib. Is there a way to reload one specified top level object from nib? Should I split the view into one NIB that can be reloaded on demand? Or is there another way to make a deep copy of the view?

Thank!

+3
source share
3 answers

, ()

[[NSBundle mainBundle] loadNibNamed:@"TheNib" owner:anObject options:nil];

SO "net" . , , Jeff LaMarche .

+2

- .

id copyOfAView = 
  [NSUnarchiver unarchiveObjectWithData:
    [NSArchiver archivedDataWithRootObject:aView]]; 

. NSNib , .

+7

, , :

if (! templEditCellView) {
  [[NSBundle mainBundle] loadNibNamed:@"TextEditCellView" owner:self options:nil];
  if (! templEditCellView) {
    abort(); // !!
  }
}
[cell.contentView addSubview: templEditCellView];
templEditCellView = nil;

.

I would like to see an approach that does not propagate nib files if I have a lot of different cell settings (as I could).

+1
source

Source: https://habr.com/ru/post/1744524/


All Articles