I have an array (called array in the code below) which contains a number of MyView objects. I am trying to iterate through these objects in a For loop and add them as a subview one by one, each after a delay of one second. The problem with the code below is that all the objects are added at once after a delay of one second. Can anyone suggest how I can correct ?
Thank you in advance.
- (void)startMethod {
for (MyView * myview in array) {
[self performSelector:@selector(addSubView:) withObject:myview afterDelay:1];
}
}
- (void)addSubView : (UIView *)view {
[soundController playSound];
[self.view addSubview:view];
}
The time to execute the loop isn’t enough to delay selectors perform. You probably need to delay yourself using for example a counter.