2011-05-03 9 views
1

테이블 뷰에서 사용자 정의 셀의 내용을 제공하기 위해 배열을 사용하고 있습니다. 뭐가 잘못 됐는지 압니다.하지만 tableview를 스크롤하면 contant가 동적으로 변경됩니다.iphone : uitableview : 셀의 내용이 스크롤 할 때 변경됨

해결하기 위해 제발 도와주세요이

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *MyIdentifier = @"MyIdentifier"; 
MyIdentifier = @"tblCellView"; 
NSString *offendersImagePath = [self applicationDocumentsDirectory]; 
//NSLog(@"%@", dbPath); 
offendersImagePath=[offendersImagePath stringByAppendingPathComponent:@"Images"]; 


CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
if(cell == nil) { 
    [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; 
    cell = aCustomCell; 
    aCustomCell=nil; 
} 

NSMutableArray *tempArray;//=[[NSMutableDictionary alloc] init]; 

tempArray=[offendersNamesList objectAtIndex:indexPath.row]; 
//NSLog(@"%d",indexPath.row); 

offendersImagePath=[offendersImagePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg",[tempArray objectAtIndex:0]]]; 
NSLog(offendersImagePath); 
[[cell offendersImageView] setImage:[UIImage imageWithContentsOfFile:offendersImagePath]]; 
[cell.offendersNameLbl setText:[tempArray objectAtIndex:1]]; 
[cell.offendersViolation setText:[tempArray objectAtIndex:2]]; 
//[tempDictionary release]; 

//[cell setLabelText:[arryData objectAtIndex:indexPath.row]]; 
return cell; 

}

+0

당신이 코드를 제공 cellForRowAtIndexPath – saadnib

+0

의 코드 일을 게시 할 수 있습니다 –

답변

1

일반적으로 이러한 종류의 문제는 셀의 내용을 cellForRowAtIndexPath에 올바르게 설정하지 않는 것이 문제입니다. 셀이 화면에서 스크롤되면 시스템은이를 "Recycle Queue"(내 용어)로 덤프합니다. 새 셀이 화면 위로 스크롤되면 시스템은이 재사용 대기열에서 재사용 할 수있는 셀을 찾습니다.

하나도 찾지 못하면 처음부터 완전히 새로운 것을 만듭니다. 귀하의 경우 셀 내용을 올바르게 설정하지 않은 이유가 무엇이든 보이며 현재 변경된 사항은 올바른 내용으로 업데이트되지 않은 재활용 된 셀입니다.

정확히 어디로 가고 있는지 확실하지 않지만 새 셀에 사용하는 코드는 조금 이상합니다. 그것은 더 다음과 같아야합니다

if(cell == nil) { 
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; 
    cell = [nib objectAtIndex:0]; 
} 
0

나는 당신의 문제가 무엇인지 100 % 아니지만,이 변수 텍스트 길이가 항목을 그리고 경우 셀의 항목이 '때로 믿을 수 크기가 점점 커지기 때문에 그것은 셀에 포함 된 레이블의 zing이 업데이트되지 않고 텍스트가 변경됩니다.

cellForRowAtIndexPath에서 조회를 수행하는 것에 대한 메모는 viewDidLoad에서 배열 (객체/사전)을 구성해야보다 효율적입니다.

참고로 .jpg 파일을 사용하는 것이 좋습니다. .png 파일을 컴파일 할 때 크기가 작아지면 사용하는 것이 더 좋습니다.

또한 NSMutableArray * tempArray를 사용합니다. 하드 코딩 된 인덱스는 매우 나쁜 습관입니다. 배열에서 위치가 바뀌면 모든 코드를 변경해야합니다. 열쇠가 덜 변하기 쉽도록 NSDictionary를 사용해보십시오.

관련 문제