2013-09-06 6 views
0

내 응용 프로그램의 UITableViewController는 json 데이터 소스에서 데이터를 가져옵니다. 또한 CG를 사용하여 사용자 지정 UITableViewCell 배경을 만들었습니다. 매우 흥미로운 버그가 발생하고 이유를 모르겠습니다. 어떤 일이 일어나고 어떻게 다시 만들지를 안내해 드리겠습니다.UITableViewCell 배경이 사라 집니까?

탭하여 표보기를 입력하십시오. 테이블을 전혀 스크롤하지 않고 즉시 항목을 볼 수 있습니다. 해당 항목을 두드린 후 뒤로 단추를 눌러 표보기로 돌아갑니다. 그런 다음 화면을 벗어난 첫 번째 셀을 아래로 스크롤하면 내 맞춤 배경이 지워지지 않습니다. 그것은 단지 셀의 기본값이 될 것입니다. 그런 다음 10 번 셀마다 아래로 계속 스크롤하면 동일한 문제가 발생합니다.

이 버그는이 정확한 프로세스에서만 발생합니다. 항목을두기 전에 테이블보기를 전혀 스크롤하지 않으면 발생하지 않을 것입니다.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Will remove all of the used codes from the table if setting is enabled 
    if (self.shouldHideCodes) { 
     NSMutableArray *tempArray = [self.jsonCodeData mutableCopy]; 
     [tempArray removeObjectsInArray:[self.usedCodes usedCodes]]; 
     self.jsonCodeData = tempArray; 
    } 

    return [self.jsonCodeData count]; 
} 


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

    if (self.jsonCodeData) { 
     cell = [tableView dequeueReusableCellWithIdentifier:@"code cell"]; 

     if ([cell isKindOfClass:[CodeCellTVC class]]) { 
      CodeCellTVC *tvcCell = (CodeCellTVC *)cell; 

      if (![tvcCell.backgroundView isKindOfClass:[CustomCellBackground class]]) { 
       tvcCell.backgroundView = [[CustomCellBackground alloc] init]; 
      } 

      NSDictionary *codeDict = [self.jsonCodeData objectAtIndex:indexPath.row]; 


      // Retrieve code string from dictionary 
      NSString *codeText = [NSString stringWithFormat:@"%@", [codeDict objectForKey:@"code"]]; 

      tvcCell.codeTableLabel.text = codeText; 

     } 
    } 

    return cell; 
} 

날이 어떻게 반응이다 혼동 것은 :

는 여기에있는 tableview 컨트롤러 관련 코드입니다. 버그가 발생할 때마다 매 10 번째 세포에는 모든 것이 아닌 문제가 있습니다. 나는 tableviewcell 그 자체를 다루는이 메소드 밖에는 아무것도 가지고 있지 않다.

+0

if 문을 통해 항상 참임을 보증합니까? 왜냐하면 그렇지 않다면 재사용 성 문제가 발생할 수 있기 때문입니다. – Arcanfel

답변

0

당신의 문제를 이해했습니다. 셀을 초기화 할 때마다 잘못했기 때문에 셀을 초기화 할 때마다 메모리가 그 셀에 할당 될 때마다 메모리 문제가 발생합니다. 아래 코드를 편집하면 효과가 있습니다.

cell = [tableView dequeueReusableCellWithIdentifier:@"code cell"]; 

    if(cell == nil) 
    { 
     cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"code cell"]; 
    } 
+0

안녕하세요 @anasuya .. –

+0

안녕하세요 @ 제인, 제발 말해주세요 – Anasuya

+0

제발 @ mrsamkitjain @ gmail.com..lets 거기에 채팅을 추가하십시오 –

관련 문제