Answer the question
In order to leave comments, you need to log in
How to generalize N objects?
Good day.
I have N objects. (For example, UILabel). Their names look something like this: label1, label2, label3, ..
I need to refer to each one in turn, respectively, I write a loop
for(int i=1;i<N;i++) {
//и тут нужно как то обратиться ко всем
}
Answer the question
In order to leave comments, you need to log in
create like this:
@property (nonatomic, strong) NSMutableArray *labels;
- (void)createLabels
{
self.labels = [NSMutableArray new];
for (int i = 0; i < N; i++)
{
UILabel *l = ...
//тут вставить настройку label-а то что у вас выше
[self.labels addObject:l];
[self.view addSubview:l];
}
}
for(int i = 0; i < self.labels.count; i++)
{
UILabel *l = self.labels[i];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question