我有麻烦的表视图和它的响应,因为每个单元格都有scrollView和72个标签。我知道scrollView需要首先加载所有元素,而不是在屏幕上加载,并且由于该表视图很慢,但是有没有办法在每次创建标签时分配和调用initWithFrame方法?我试图重复使用不同框架的标签,但它不起作用。桌面视图内滚动视图性能差ios
这里是代码,我需要优化某种方式来更快地创建标签。
int listSize = 36;
for(int i=0;i<listSize;i++){
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0+i*200, 0, 200, 80)];
label.text = @"HELLO";
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont fontWithName:@"ArialMT" size:18];
[scrolView addSubview:label];
UILabel *grayBorderInFront = [[UILabel alloc] initWithFrame:CGRectMake(2+i*200, 5, 1, scrolView.frame.size.height-10)];
grayBorderInFront.text = @"";
grayBorderInFront.backgroundColor = [UIColor lightGrayColor];
[scrolView addSubview:grayBorderInFront];
}
你想才达到什么?也许如果你向我们展示一些代码,我们可以帮助你。 – amb
我希望我的数据在滚动视图(左侧和右侧)中可滚动,但我也想向下滚动低谷列表视图。但现在,当我跌倒或跌倒时,速度太慢。 – lugonja
而不是为每个单元格创建新的标签,您应该继承UITableViewCell,并且只需在表格滚动时重置文本。您可以覆盖'prepareForReuse'来重置您的单元格为默认状态,然后设置该行标签的文本。 –