【发布时间】:2014-11-06 06:39:39
【问题描述】:
我有一个带有子视图的UIScrollView。它包含产品/项目的结果列表。 UIView与UIImageView 和UILabel。它可能包含许多项目。我的问题是当我按下按钮(网格按钮)将 UI 结果更改为网格视图时,完成处理需要时间。有没有办法让它更快?比如移除 screen/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 元素不会加载到内存中。它重用现有的单元格。
-
我正在使用
UIScrollView。我正在考虑将其更改为UITableViewfor List 和UICollectionViewfor Grid。你怎么看? -
我建议进行切换。 UiTableView 和 UICollectionView 就是为此目的而设计的。 UIScrollView 并不是真的要处理任意数量的动态渲染。一开始会有点复杂,但你会发现 UITableView/UICollectionView 为你做了很多工作。
-
还有一个问题,
UITableView和UICollectionView可以同时使用,隐藏和显示吗?这会是内存的问题吗?两者都包含相同的产品/项目。
标签: ios objective-c xcode uiscrollview