我有一個UIScrollView
子視圖。它包含產品/項目的結果列表。與UIImageView
和UILabel
。它可能包含很多項目。我的問題是,當我按下按鈕(網格按鈕)將UI結果更改爲網格視圖時,它在完成處理之前需要時間。有沒有辦法讓這個更快?像刪除在屏幕/ UIScrollView中不可見的圖像?有很多子視圖的UIScrollView需要時間來處理
這裏是我的ListView控件
代碼-(void)actionList {
NSLog(@"List!!");
isGrid = NO;
for(UIView*iView in sv_results.subviews){
for(UILabel *iView2 in iView.subviews){
if([iView2 isMemberOfClass:[UILabel class]]){
if(iView2.tag == 0)
{
iView2.frame = CGRectMake(80, 0, 150, 50);
iView2.font = [UIFont boldSystemFontOfSize:12.0f];
}
else if(iView2.tag == 1)
{
pricewidth = [iView2.text sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13.0f]}];
iView2.frame = CGRectMake(80, 20, pricewidth.width+1, 50);
iView2.font = [UIFont systemFontOfSize:13.0f];
for(UIView *discountline in iView2.subviews)
{
discountline.frame = CGRectMake(0, iView2.frame.size.height/2, iView2.frame.size.width, 1);
}
}
else if(iView2.tag == 2)
{
iView2.frame = CGRectMake(screenRect.size.width-60, 30, 50, 15);
iView2.font = [UIFont systemFontOfSize:10.0f];
}
else if(iView2.tag == 3)
{
iView2.frame = CGRectMake(140, 20, 150, 50);
iView2.font = [UIFont systemFontOfSize:13.0f];
}
else {
iView2.frame = CGRectMake(80, 0, 150, 50);
iView2.font = [UIFont boldSystemFontOfSize:12.0f];
}
}
if([iView2 isMemberOfClass:[AsyncImageView class]]){
iView2.frame = CGRectMake(15,12,50,50);
iView2.layer.cornerRadius = 5;
}
}
for(int i = 0;i<=allAvailableData;i++)
{
if(iView.tag == i)
{
iView.frame = CGRectMake(0,((i-1)*75),320,75);
}
//sv_results.contentSize = CGSizeMake(320,yPosition);//optional resize height scrollview from gridview
}
iView.layer.borderWidth = .3f;
}
sv_results.contentSize = CGSizeMake(320,(allAvailableData)*75);
}
你基本上是問一個UITableView是否存在,答案是肯定的。當UITableViewCell當前不在屏幕上可見時,UI元素不會加載到內存中。它重新使用現有的單元格。 – 2014-11-06 06:45:36
我正在使用'UIScrollView'。我正在考慮將它更改爲List的「UITableView」和Grid的'UICollectionView'。你怎麼看? – 2014-11-06 06:48:27
我會建議做這個開關。 UiTableView和UICollectionView是爲此目的而設計的。 UIScrollView實際上並不是要處理任意數量的動態呈現。起初它會稍微複雜一點,但你會發現UITableView/UICollectionView爲你做了很多工作。 – 2014-11-06 06:52:49