UITableView가있는 UIViewController가 매우 느립니다 (당밀로 느림) 아마도 그룹화 된 UITableview의 UITableViewCells에 대한 사용자 정의 배경 이미지 설정 때문일 수 있습니다. ViewController가 소유합니다. Cocoa With Love Custom UITableView Drawing사용자 정의 UITableViewCells (깨진 레코드)를 사용하여 ViewController로드 속도 향상
: 나는 또한 내가 어리석은 일을하고 있지 않다 확인하기 위해이 문서를 따랐습니다 Tricks for improving iPhone UITableView scrolling performance:
나는 추천이 다른 SO 질문에 명시된 바와 같이 나는만큼 다음과 같아
배경 스타일 코드를 호출하지 않는 즉시 성능이 향상됩니다.
제안에 따라, 내가 뭘 모든 단계 : 때문에 디자인이 방법의
- , 나는 2 개의 다른 세포 변화가 균일 한 행 높이를 가질 수 없습니다. 셀 변형에 관계없이 행 배경은 항상 3 개의 이미지 중 1 개이며 행 인덱스를 기반으로합니다. 0 : top_row_image, n-1 : bottom_row_image, 기타 모두 : middle_row_image
- 내 ViewController의 viewDidLoad에서 배경에 사용 된 이미지를로드하고 있습니다. 내가
- 세포의 층이
- 이 뾰족 셀을로드하지 재사용되고 불투명
- 셀 식별자로 설정되어 있는지 셀 핸들 내부의 UITextField를시키는거야으로
- 나는 어떤의 drawRect 코드가없는
는 기본적으로, 다른 상단되는 행의 유형은 그것이 입력 따라 중간과 맨 아래 행의 배경 이미지와 테이블의 섹션의 행의 각 스타일을 원하는 파일. 누구든지 UITableView에 사용자 지정 배경을 가지고 더 나은 방법을 제안 할 수 있습니까? 난 당신이 cellForRowAtIndexPath
에 모든 호출에 모든 단일 셀의 배경 이미지를 전환 중지 경우 상당한 성능 향상을 볼 수있을 거라 생각
ViewController:
@property (nonatomic, weak) IBOutlet *tableview;
@property (nonatomic, strong, readwrite) UIImage *topRowImage;
@property (nonatomic, strong, readwrite) UIImage *middleRowImage;
@property (nonatomic, strong, readwrite) UIImage *bottomRowImage;
@synthesize tableview = _tableview;
@synthesize topRowImage = _topRowImage;
@synthesize middleRowImage = _middleRowImage;
@synthesize bottomRowImage = _bottomRowImage;
// Load the images that will be used for the cell background ahead of time
- (void)viewDidLoad
{
[super viewDidLoad];
// All of the images are 60x20 but my cells are 300x44 or 300x56
UIEdgeInsets edgeInsets = UIEdgeInsetsMake(2, 4, 2, 4);
self.topRowImage = [[UIImage imageNamed:@"top_row.png"] resizableImageWithCapInsets:edgeInsets];
UIEdgeInsets edgeInsets = UIEdgeInsetsMake(0, 4, 0, 4);
self.middleRowImage = [[UIImage imageNamed:@"middle_row.png"] resizableImageWithCapInsets:edgeInsets];
edgeInsets = UIEdgeInsetsMake(2, 4, 2, 4);
self.bottomRowImage = [[UIImage imageNamed:@"bottom_row.png"] resizableImageWithCapInsets:edgeInsets];
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellId = [self getCellIdAt:indexPath];
BaseCustomTableViewCell *cell = (BaseCustomTableViewCell *)[aTableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil)
{
if ([cellId isEqualToString:@"CellId1"])
{
cell = [[CustomTableViewCell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
else
{
cell = [[CustomTableViewCell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
}
// the following line seems to be the bottleneck
[self styleBackground:cell indexPath:indexPath totalRows:totalRows];
[cell configureData:myRowData];
}
- (void)styleCellBackground:(BaseCustomTableViewCell *)cell
indexPath:(NSIndexPath *)indexPath
totalRows:(NSInteger)totalRows
{
UIImage *backgroundImage = nil;
if (indexPath.row == 0)
{
// Top row of this section
backgroundImage = self.topRowImage; // ivar loaded during 'viewDidLoad'
}
else if (indexPath.row == totalRows - 1)
{
// Bottom row of this section
backgroundImage = self.bottomRowImage;
}
else {
// Middle row of this section
backgroundImage = self.middleRowImage;
}
[cell updateRowBackground:backgroundImage];
}
@implementation CustomTableViewCell
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
{
// Create my text field
_textField = [[UITextField alloc] initWithFrame:CGRectZero];
_textField.backgroundColor = [UIColor whiteColor];
self.backgroundColor = [UIColor whiteColor];
self.contentView.backgroundColor = [UIColor whiteColor];
self.backgroundView = [[UIImageView alloc] init];
// not sure which of these should be set to opaque to ensure to meet criteria #4
// 4. Make your UITableViewCell's layer opaque (same goes for the content view if you have one)
self.backgroundView.opaque = YES;
self.layer.opaque = YES;
self.opaque = YES;
self.contentView.opaque = YES;
[self.contentView addSubview:_textField];
}
}
- (void)layoutSubviews
{
CGRect textFieldFrame = CGRectMake(10, 2, 278, 40);
self.textField.frame = textFieldFrame;
[super layoutSubviews];
}
- (void)updateRowBackground:(UIImage *)rowBackground
{
((UIImageView *)self.backgroundView).image = rowBackground;
}
혼란 스럽지만 모든 셀마다 배경이 다른가요? 얼마나 많은 세포가 있습니까? 각기 다른 배경을 가진 셀이 많은 경우에는 동적으로로드해야합니다. viewdidload에서 모든 것을로드하면 인터페이스가 모든 준비가 완료 될 때까지 대기하게됩니다. 또한 디버깅을하고 많은 셀을 가지고 있다면 로딩 시간을 많이 늘리는 NSLOG를 사용하지 마십시오. – Pochi
3 가지 배경 유형이 있습니다.각 섹션의 상단 행 셀은 1 유형 (아래로 곡선이 있음), 가운데 행은 다른 표준 이미지 (표준 이미지) 및 마지막으로 각 섹션의 맨 아래 행에 세 번째 유형 (이 이미지에는 위쪽 곡선이 있음)이 있어야합니다. –
총 15 개의 행이 있으며 4 개의 섹션으로 나뉩니다. –