내 UITableView에서 래그를 없애고 싶다면 내 성능이 어떻게 향상되는지 모르겠다.사용자 정의 셀을 사용하는 UITableView의 성능 향상
1 - 6 개의 맞춤 셀이 있습니다. 2 - 셀이 확장되거나 축소됩니다. 3 - 확장 가능한 셀 중 하나가 확장되면 다른 간단한 셀이 목록을 만드는 아래에 생성됩니다.
다른 종류의 셀을 처리 할 때 코드가 복잡해졌습니다. 그들 각각은 다른 행동과 다른 높이를 가지고 있습니다.
나는 그것에 대해 다른 사람들의 질문을 읽고, 누군가가이 방법에 전달할 때 jQuery과 개선 할 수있는 것들 중 하나는 높이에 캐시의 어떤 종류를 만드는 것입니다 말했다
* I 돈 캐시하는 법을 알지 못해서 이것이 내 문제에 도움이 될지 모르겠습니다. 지금 얼마나
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
내 코드 :
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
BOOL isChild =
currentExpandedIndex > -1
&& indexPath.row > currentExpandedIndex
&& indexPath.row <= currentExpandedIndex + [[subItems objectAtIndex:currentExpandedIndex] count];
if (indexPath.row == 0) {
return 117;
}
if (currentExpandedIndex == 0) {
if (isChild && indexPath.row == currentExpandedIndex +1) {
return 175;
}else if (isChild){
return 0;
}
if (indexPath.row == currentExpandedIndex + numberOfExpandedCells + 3) {
return 15;
}
}
if (currentExpandedIndex == 2) {
if (indexPath.row == currentExpandedIndex + numberOfExpandedCells + 1) {
return 15;
}
}
if (!isChild && indexPath.row == 1) {
return 15;
}else if (!isChild && indexPath.row == 3){
return 15;
}else if (!isChild && indexPath.row == 11 + numberOfExpandedCells){
return 100;
}
return 55;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
BOOL isChild =
currentExpandedIndex > -1
&& indexPath.row > currentExpandedIndex
&& indexPath.row <= currentExpandedIndex + [[subItems objectAtIndex:currentExpandedIndex] count];
if (!isChild) {
static NSString *PanelCellIdentifier = @"PanelCell";
static NSString *ParentCellIdentifier = @"ParentCell";
static NSString *TutorialCellIdentifier = @"TutorialCell";
if (indexPath.row == 0) {
DSPanelTableViewCell *cell = (DSPanelTableViewCell *)[tableView dequeueReusableCellWithIdentifier:PanelCellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"DSPanelTableViewCell" owner:nil options:nil] objectAtIndex:0];
}
[cell configurePanelCellFor:user.recomendacoes with:user.pontos expanded:currentExpandedIndex withCalc:calc];
return cell;
}else{
DSMealTableViewCell *cell = (DSMealTableViewCell *)[tableView dequeueReusableCellWithIdentifier:ParentCellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"DSMealTableViewCell" owner:nil options:nil] objectAtIndex:0];
}
int topIndex = (currentExpandedIndex > -1 && indexPath.row > currentExpandedIndex)
? indexPath.row - [[subItems objectAtIndex:currentExpandedIndex] count]
: indexPath.row;
[cell configureMealCellWithTitles:titlesArray subTitles:subtitlesArray points:pointsArray minMax:minMax forIndex:topIndex];
if (currentExpandedIndex == 0) {
if (indexPath.row == 2 + numberOfExpandedCells){
CGRect frame = cell.title.frame;
frame.origin.y += 8;
cell.title.frame = frame;
cell.subTitle.hidden = YES;
}
}else if (indexPath.row == 2 || indexPath.row == 9 + numberOfExpandedCells) {
CGRect frame = cell.title.frame;
frame.origin.y += 8;
cell.title.frame = frame;
cell.subTitle.hidden = YES;
}else{
cell.subTitle.hidden = NO;
}
if (indexPath.row == 10 + numberOfExpandedCells) {
DSTutorialTableViewCell *cell = (DSTutorialTableViewCell *)[tableView dequeueReusableCellWithIdentifier:TutorialCellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"DSTutorialTableViewCell" owner:nil options:nil] objectAtIndex:0];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.delegate = self;
cell.cellIndex = indexPath.row;
return cell;
}
if ((currentExpandedIndex == 0 && indexPath.row == currentExpandedIndex + numberOfExpandedCells + 3) ||
(currentExpandedIndex == 2 && indexPath.row == currentExpandedIndex + numberOfExpandedCells + 1) ||
(indexPath.row == 1 || indexPath.row == 3 || indexPath.row == 11 + numberOfExpandedCells)) {
cell.userInteractionEnabled = NO;
cell.hidden = YES;
}else{
cell.userInteractionEnabled = YES;
cell.hidden = NO;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
}else{
static NSString *PanelCellIdentifier = @"PanelCell";
static NSString *ButtonCellIdentifier = @"ButtonCell";
static NSString *ChildCellIdentifier = @"ChildCell";
if (indexPath.row == currentExpandedIndex +1) {
if (currentExpandedIndex == 0) {
DSPanelInfoTableViewCell *cell = (DSPanelInfoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:PanelCellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"DSPanelInfoTableViewCell" owner:nil options:nil] objectAtIndex:0];
}
[cell configurePanelInfoCellWithPontos:user.pontos withCalc:calc];
return cell;
}
DSButtonsTableViewCell *cell = (DSButtonsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:ButtonCellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"DSButtonsTableViewCell" owner:nil options:nil] objectAtIndex:0];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.delegate = self;
cell.cellIndex = indexPath.row;
return cell;
}
DSItemTableViewCell *cell = (DSItemTableViewCell *)[tableView dequeueReusableCellWithIdentifier:ChildCellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"DSItemTableViewCell" owner:nil options:nil] objectAtIndex:0];
}
if (currentExpandedIndex == 0) {
cell.userInteractionEnabled = NO;
cell.hidden = YES;
return cell;
}
NSDictionary* dict = [[subItems objectAtIndex:currentExpandedIndex] objectAtIndex:indexPath.row - currentExpandedIndex - 1];
[cell configureItemCellWithDetails:dict];
return cell;
}
}
알아요 .. 와우 이것은 jQuery과를 처리하기 위해 너무 많은 코드입니다 ...하지만 난 그것을 개선하는 방법을 모르겠어요. 이 코드는 제대로 작동하지만 tableview의 성능이 좋지 않습니다. 누구든지 도와 줄 수 있습니까?
교육용 추측 : .xib에있는 셀에 대해 'reuseIdentifier'를 설정하지 않았습니까? 그렇지 않은 경우 프로파일 러 (Instruments)를 사용하여 성능 저하의 원인이되는 코드 부분을 판별하십시오. –
그것은 작동했습니다 ... 나는 xib에 식별자를 설정하지 않았습니다 ... 덕분에 많이 !! XD – rihurla
그 점을 잘 알고 있으면 대답에 대한 내 의견이 바뀌었다. –