我在这里尝试使用 scrollView 构建扩展视图,所以我的类是:
ButtonsScroller.h
这是我的组件类,这个类扩展了 UIView 并有 uiscrollview
这是这个类的主要方法
-(void)buildUi {
buttonsCount=[buttonsArray count];
NSLog(@"Building Scroll With %d Buttons",buttonsCount);
NSLog(@", every row has %d Buttons",countOfButtonsInOneRow);
NSLog(@", every button Width is : %d px",buttonWidth);
NSLog(@", every button height is : %d px",buttonHeight);
NSLog(@", space Between Buttons In One Row is : %d px",marginsBetweenButtons);
NSLog(@", space Between 2 rows is : %d px",marginsBetweenRows);
NSLog(@"and number Of Rows To Be Shown : %d row",rowsToShow);
int horizontalStart=horizontalStartFrom-buttonWidth;
int HORIZONTAL_CORDENATES=horizontalStart;
for(int bc=0;bc<buttonsCount;bc++){
NSLog(@"buttons Counter : %d",bc);
for(int g=0;g<countOfButtonsInOneRow;g++){
if(bc==buttonsCount || bc>buttonsCount){
break;
}else {
Expos *expo=[buttonsArray objectAtIndex:bc];
//ExpoUIButton : My Custom UIView with buttons in it
ExpoUIButton *btn=[[ExpoUIButton alloc]init];
[btn.name setText:expo.userName];
if(![expo.user_type isEqualToString:@"2"]){
NSLog(@"[expo.user_type isEqualToString:1");
[btn setType:0];
}
btn.frame=CGRectMake(HORIZONTAL_CORDENATES, VERTICAL_CORDENATES, buttonWidth, buttonHeight);
[scrollView addSubview:btn];
bc=bc+1;
HORIZONTAL_CORDENATES=HORIZONTAL_CORDENATES-(marginsBetweenButtons+buttonWidth);
}
NSLog(@"g : %d",g);
}
bc=bc-1;
HORIZONTAL_CORDENATES=horizontalStart;
VERTICAL_CORDENATES=VERTICAL_CORDENATES+(marginsBetweenRows+buttonHeight);
}
// ComputeRow Count
int rowCount=buttonsCount;
// NSLog(@"rowCount%4 : %d",(rowCount%4 ));
while((rowCount%countOfButtonsInOneRow) !=0){
NSLog(@"rowCount : %d",rowCount);
rowCount=rowCount+1;
}
float rowCounts=(rowCount/countOfButtonsInOneRow);
NSLog(@"rowCounts : %f",rowCounts);
float viewHeight=rowsToShow*(buttonHeight)+(rowsToShow*marginsBetweenRows)+(buttonHeight/2);
NSLog(@"viewHeight : %f",viewHeight);
if(self.showLoadMore){
if(loadMore==nil){
loadMore=[UIButton buttonWithType:UIButtonTypeCustom];
[loadMore setImage:[UIImage imageNamed:@"more"] forState:UIControlStateNormal];
[loadMore setImage:[UIImage imageNamed:@"more-f"] forState:UIControlStateHighlighted];
[loadMore setFrame:CGRectMake(130, VERTICAL_CORDENATES+3, 68, 15)];
[scrollView addSubview:loadMore];
}else {
[loadMore setFrame:CGRectMake(130, VERTICAL_CORDENATES+3, 68, 15)];
}
[scrollView setContentSize:CGSizeMake(SC_WIDTH, VERTICAL_CORDENATES+25)];
}else {
[scrollView setContentSize:CGSizeMake(SC_WIDTH, VERTICAL_CORDENATES)];
}
}
在我的 mainView 控制器中,我启动了一个连接,当连接完成时调用此方法
#pragma mark -
#pragma mark - YttpConnectionDelegate
-(void) YConnectionDoneWithArray:(NSMutableArray *)items {
NSLog(@"items : %d",[items count]);
if([items count]>0 ){
exposArray =items;
[productsList hideLoadingView];
[productsList setButtonsArray:exposArray];
[productsList buildUi ];
SEL selector = @selector(loadDataFromInternet);
[productsList loadMoreBtnSelector:selector target:self];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
} else {
[productsList hideLoadingMoreButton];
}
}
当我打开我的视图并加载第一组按钮时,视图仍然可以,但是当添加第二组按钮时出现问题,uiscrollview 变得粗糙并且所有按钮(旧按钮和新按钮)都不可点击
另外,如果我回到我的 firstVC 视图,然后在加载第一组按钮后转到 scrollviewVC 屏幕,所有按钮仍然不可点击,那么问题是什么?!
编辑 :
因为我认为这是一个刷新问题?!