2011-06-11 5 views
1

첨부 된 세그먼트 화 된 제어 값을 기반으로 제공된 두 개의 데이터 세트 중 하나를 사용하여 내용이 채워진 테이블이 있습니다. 데이터는 웹에서 가져옵니다.세그먼트 화 된 UITable의 불안정

두 데이터 집합간에 앞뒤로 이동 한 다음 표 셀을 선택하면 응용 프로그램이 충돌합니다. 분할 된 컨트롤이있는 단일 테이블이 아닌 두 개의 개별 테이블을 사용할 때 딸꾹질없이 응용 프로그램이 작동합니다. 어떻게 든 그들을 결합하면 응용 프로그램이 불안정 해집니다.

가장 큰 오류 중 하나는 내가 Acells of A 테이블을 탭했을 때로드가 세그먼트 인덱스 = 1을 두드리는 동안 B가로드되어 인식 할 수없는 선택기가 전송됩니다. 매개 변수의 의미 o B 테이블로 보내지는 테이블.

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier0; 
    if (choice == 0) { 
     CellIdentifier0 = @"ACell"; 
    } else if (choice == 1) { 
     CellIdentifier0 = @"BCell"; 
    } 

    UITableViewCell *cell; 

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0]; 
    if (cell == nil) { 
     if (choice == 0) { 
      [[NSBundle mainBundle] loadNibNamed:@"ACell" owner:self options:nil]; 
     cell = ACell; 
      self.ACell = nil; 
     } else if (choice == 1) { 
      [[NSBundle mainBundle] loadNibNamed:@"BCell" owner:self options:nil]; 
      cell = BCell; 
      self.BCell = nil; 
     } 
    } 

    if (choice == 0) { 
     [(ACell *)cell setA:(A*)[contentArray objectAtIndex:indexPath.row]]; 
    } else if (choice == 1) { 
     [(BCell *)cell setB:(B*)[contentArray objectAtIndex:indexPath.row]]; 
    } 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (choice == 0) { 
     A = [contentArray objectAtIndex:indexPath.row]; 
     [[NSNotificationCenter defaultCenter] postNotificationName:@"showA" object:A]; 
    } else if (choice ==1) { 
     B = [contentArray objectAtIndex:indexPath.row]; 
     [[NSNotificationCenter defaultCenter] postNotificationName:@"showB" object:B]; 
    } 
} 
+2

이것은 셀을 재사용 할 때 문제가 될 수 있습니다. ** 코드 ** 없이는 말할 길이 없습니다. – PengOne

+0

보유 코드가 도움이되지 않는 – lilzz

답변

0

가 이전 값을 해제하고 nilACell을 설정합니다 self.ACell = nil;을하고, nib 파일이로드 될 때 ACell이 유지 값을 가지고 있다고 가정 철자. 이제 이전 값은 cell이 가리키는 값입니다. 따라서 기술적으로는 ACell이 개체를 유지하는 유일한 변수이기 때문에 할당 취소 된 것처럼 정크를 가리킬 수 있습니다. 당신은 didSelectRowAtIndexPath: 방법 당신은 } else if (choice = 1) {을하고있는하는 (!) 참고로, 교체함으로써와

cell = ACell; 

,

cell = [[ACell retain] autorelease]; 

을이 문제를 해결할 수 있습니다. 항상 이 아닌 ==을 사용해야합니다.이 경우에는 가능성이 희박하지만 choice 값을 변경하면서 항상 true로 평가됩니다.

+0

입니다. – lilzz

+0

@ user482473'didSelectRowForIndexPath :'메소드를 추가 할 수 있습니까? –

+0

물론 표 A와 표 B의 개별 셀 (Acell 또는 Bcell)을 선택할 수 있습니다. – lilzz

0

체크 선택은

if (choicee==0) { 
[[NSBundle mainBundle] loadNibNamed:@"ACell" owner:self options:nil]; 
    cell = ACell; 
    self.ACell = nil;} 
else if (choice==1) { 
관련 문제