我已创建了一个滚动视图和上滚动视图滚动视图,我加入两个交替的自定义的UIView小号添加视图到
@interface FirstView : UIView
@interface SecondView : UIView
我的阵列是
NSMutableArray *classArray= [[NSMutableArray alloc] initWithObjects:firstView, secondView, firstView, secondView, nil];
我在添加视图在下面的方式滚动视图
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)];
我得到输出上只有两个滚动视图定制的意见,但我想有应该是滚动视图上的5个自定义视图
请帮我解决这个问题。
我加入的UIScrollView的 – 2011-12-21 09:56:42
我知道所有的UIView,而是看你的阵列 “[[NSMutableArray的页头] initWithObjects:的firstView,secondView,的firstView,secondView,零]。”您多次使用相同的实例。您需要为屏幕上的每个UIView创建唯一的UIView实例,它们可以具有相同的类型/类。这意味着* view1 = [FirstView alloc] init],* view2 = [[FirstView alloc] init],* view3 = [[SecondView alloc] init],* view4 = [[SecondView alloc] init] .... etc – bandejapaisa 2011-12-21 10:01:31