I have created one scroll view and on the scroll view, i am adding two alternate custom UIView s
@interface FirstView : UIView
@interface SecondView : UIView
my array is
NSMutableArray *classArray= [[NSMutableArray alloc] initWithObjects:firstView, secondView, firstView, secondView, nil];
i am adding views on scroll view in following manner
for ( i = 0 ; i< 5; i++)
{
UIView *userView = [classArray objectAtIndex:i];
CGRect rect;
rect.size.height = KVIEWHGT;
float userViewWidth = userView.frame.size.width;
rect.size.width = userViewWidth;
userView.frame = rect;
[scrollView addSubview:userView];
[userView release];
}
UIView *userView = nil;
NSArray *userSubViews = [scrollView subviews];
CGFloat x = 0;
float userViewWidth = 0.0f;
for (userView in userSubViews) {
if ([userView isKindOfClass:[UIView class]]){
CGRect frame = userView.frame;
frame.origin = CGPointMake(x, 0);
userView.frame = frame;
userViewWidth = userView.frame.size.width;
x += userViewWidth + 10;
}
}
[scrollView setContentSize:CGSizeMake(x, scrollView.frame.size.height)];
I am getting output as only two custom views on scroll view but i want there should be 5 custom view on the scroll views
Please help me to solve this problem.
You are adding firstView ,secondView multiple time in the array, even though you add it multiple time it refers to the same instance