2014-07-06 2 views
0

사용자 지정 이미지가있는 구분선 셀을 사용하려고합니다. 내 cellForRowAtIndexPath에서스크롤시 UITableViewCell 구분선이 사라집니다.

: 나는 그런 일을 시도했다

NSString *cellIdentifier = [NSString stringWithFormat:@"identifier"]; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 
} 

cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:19]; 
cell.textLabel.text = [self.menuItems objectAtIndex:indexPath.row]; 
cell.textLabel.textColor = [UIColor colorWithRed:128/255.0f green:129/255.0f blue:132/255.0f alpha:1.0f]; 
cell.backgroundColor = [UIColor whiteColor]; 

UIImageView *imagView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"reaL.png"]]; 
imagView.frame = CGRectMake(0, cellHeight, cellWidth, 1); 
[cell.contentView addSubview:imagView]; 

switch (indexPath.row) { 
    case 0: 
     cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"img1.png"] scaledToSize:CGSizeMake(27, 27)]; 
     cell.imageView.highlightedImage = [self imageWithImage:[UIImage imageNamed:@"route.png"] scaledToSize:CGSizeMake(27, 27)]; 
     break; 
    case 1: 
     cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"img.png"] scaledToSize:CGSizeMake(27, 27)]; 
     cell.imageView.highlightedImage = [self imageWithImage:[UIImage imageNamed:@"money.png"] scaledToSize:CGSizeMake(27, 27)]; 
     break; 
    case 2: 
     cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"auto.png"] scaledToSize:CGSizeMake(27, 27)]; 
     cell.imageView.highlightedImage = [self imageWithImage:[UIImage imageNamed:@"cars.png"] scaledToSize:CGSizeMake(27, 27)]; 
     break; 
    case 3: 
     cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"impostazioni.png"] scaledToSize:CGSizeMake(27, 27)]; 
     cell.imageView.highlightedImage = [self imageWithImage:[UIImage imageNamed:@"impostazioni.png"] scaledToSize:CGSizeMake(27, 27)]; 
     // cell.imageView.contentMode = UIViewContentModeScaleAspectFill; 
     break; 
    case 4: 
     cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"info.png"] scaledToSize:CGSizeMake(27, 27)]; 
     cell.imageView.highlightedImage = [self imageWithImage:[UIImage imageNamed:@"info.png"] scaledToSize:CGSizeMake(27, 27)]; 
     break; 
    default: 
     break; 
} 

return cell; 

때 나는 점심 응용 프로그램의 모든 좋은,하지만 난 테이블을 스크롤하거나 때 내가 분리 라인이 사라 셀을 선택합니다. 영구적 인 사용자 정의 줄 구분 기호는 어떻게 가질 수 있습니까?

+0

왜 분리 기호 이미지를 사용하고 있습니까? 그것은 그것을 보완하는 올바른 방법이 아닙니다. 우리는 당신이 더 나은 방법을하도록 도울 수 있습니다. – duci9y

+0

안녕하세요, 어떻게 설명 할 수 있습니까? – iconso

+0

왜 이미지를 구분 기호로 사용하는지 말해줘야합니다. – duci9y

답변

0

처음부터 올바르게 셀을 만들지 않습니다. 실행중인 문제에 도움이 될만한 몇 가지 팁을 소개합니다.

우선 ios6부터 Apple은 이제 우리가 셀을 대기열에서 빼내기 위해 사용하는 클래스를 미리 등록 할 수있게하여 더 이상 셀 검사를 수행 할 필요가 없습니다. 같이이 제대로마다 셀을 큐에서 제거 할 수

[self.tableView registerClass:[CustomTableViewCellClass class] forCellReuseIdentifier:customIdentifier]; 

:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:customIdentifier]; 

다음,이는보기 부하를했다, 당신은 유사한 무언가를 할 수 있습니다 나는 당신이 문제에 직면하고 있다고 생각합니다. 셀을 대기열에 추가 할 때마다 이미지보기를 만들어 셀에 추가하고 있습니다.

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"reaL.png"]]; 
imageView.frame = CGRectMake(0, cellHeight, cellWidth, 1); 
[cell.contentView addSubview:imageView]; 

는 당신은 셀이 그렇지 않으면 당신은 셀의 상단에 지속적으로 셀이 다시 사용할 때마다 UIImageViews를 추가 할 겁니다 생성이 처음으로 할 필요가있다. 이 상황에 대한 더 나은 패턴은 사용자 지정 셀 자체에 대한 UIImageView * 참조를 갖는 것입니다. 셀이 대기열에서 제외되면 이미지와 프레임을 설정합니다. 이렇게하면 UIImageView는 한 번만 만들어지고 한 번 셀에 추가됩니다.

행운을 빈다.

관련 문제