2014-03-30 13 views
0

사용자 지정 UITableViewCell이 있는데 여기에 UIPickerView가 있습니다. 이를 관리하기 위해 UIPickerView 대리자 및 데이터 소스 메서드를 구현 한 Subclass를 만들었습니다. cellForRowAtIndexPath 내가 이런 식으로 구현되는 경우 : 서브 클래스하는 .m 파일에사용자 지정 UITableViewCell 내의 UIPickerView

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

    if (indexPath.section==2) { 

     PickerCellTableViewCell *cell2=[tableView dequeueReusableCellWithIdentifier:@"pickerCell" forIndexPath:indexPath]; 
     cell2.cellPickerInputArray=self.pickerArray; 

     return cell2; 

    }else{ 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"normalCell" forIndexPath:indexPath]; 

     cell.textLabel.text=[[self.inputArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; 

     return cell; 

    } 
} 

나는 다음과 같은 한 :

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { 

     return [self.cellPickerInputArray count]; 

} 

나는 다음과 같은 문제가있다 :이처럼두면 충돌과 콘솔이 나에게주는이 :

잘못된 갱신 : 섹션 0의 행 개수가 잘못 업데이트 후 기존 섹션에 포함 된 행의 수 (7),691,363를해야합니다 (0이 삽입되고 0이 삭제됨) 에서 삽입 또는 삭제 된 행 수를 더하거나 뺀 수 및 더하기 또는 빼기 수 행 수를 더한 것보다 앞의 해당 섹션에 포함 된 행 수와 같습니다. (0은 안으로 움직이고 0은 밖으로 움직였다). " 나는 numberOfRowsInComponent 변경하는 경우

그러나 (이 예에서는 7) 실제 행 수를 반환하기를, 모든 것을 꽤 잘 작동합니다.

나는 해봤지만 문제/해결책을 찾지 못했다. 어떤 도움을 주시면 감사하겠습니다. 미리 감사드립니다!

편집! @meda에 의해 NSLoged NSLog(@"PickerInputArray count"%@",[self.cellPickerInputArray 카운트]에 의해 sugested); 방법 pickerView numberOfRowsInComponent 다음

내부 : 당신의 로그에서

2014-03-30 21:04:54.756 TestPickerOnTable[3498:60b] PickerInputArray count0 
2014-03-30 21:04:54.757 TestPickerOnTable[3498:60b] PickerInputArray count0 
2014-03-30 21:04:54.758 TestPickerOnTable[3498:60b] PickerInputArray count0 
2014-03-30 21:04:54.758 TestPickerOnTable[3498:60b] PickerInputArray count0 
2014-03-30 21:04:54.762 TestPickerOnTable[3498:60b] PickerInputArray count7 
2014-03-30 21:04:54.765 TestPickerOnTable[3498:60b] PickerInputArray count7 
2014-03-30 21:04:54.767 TestPickerOnTable[3498:60b] PickerInputArray count7 
2014-03-30 21:04:54.770 TestPickerOnTable[3498:60b] PickerInputArray count7 
2014-03-30 21:04:54.771 TestPickerOnTable[3498:60b] PickerInputArray count7 
2014-03-30 21:04:54.771 TestPickerOnTable[3498:60b] PickerInputArray count7 
+0

는'NSLog (%의 @ ", [self.cellPickerInputArray 수를]"PickerInputArray 카운트 "@) 로그, 그렇지 않은 경우' 7과 같으면 whyt를 찾아야합니다 – meda

+0

그래, 이미 시도했습니다. 위의 편집을 참조하십시오. – Marcal

답변

0

것 같습니다 당신의 UIPicker 데이터 소스 변경의 요소 수.

self.inputArray에서 요소를 추가하거나 삭제할 때 항상 구성 요소를 다시로드해야합니다. 그렇지 않으면 잘못된 업데이트 오류가 발생합니다.

는 선택기 다시로드하려면 : 2 년 전이 질문을

[_yourPicker reloadAllComponents] 
+0

self.inputArray는 정적 배열이며 변경되지 않습니다.또한 내가 이해하지 못하는 이유는 "numberOfRowsInComponent"가 10 번 호출 된 이유입니다 ... – Marcal

+0

그래, 제가 섹션 2의 모든 행에 대해 해당 셀을 반환한다는 것을 알았습니까? – meda

+0

아니요. 또한 inputArray 내용이 16 개 항목 인 경우이 피커 메서드가 호출되는 시간은 동일합니다 (10 번). – Marcal

0

을, 그래서 당신은 아마 이미 그것을 해결했지만, 문제는 cellForRowAtIndexPath에 당신이에 따라 세포의 두 가지 종류를 만들 수 있다는 것입니다 IndexPath.section의 값.

if indexPath.section == 2의 (사용자 지정) 셀은 cellPickerInputArray입니다. 그렇지 않으면 귀하의 (정상적인) 셀에 그 값이 없으므로 numberOfRowsInComponent이 실패합니다.

것은이 문제를 해결하려면, 같은 if..then..else 구조를 가지고 당신의 numberOfRowsInComponent을 변경

if (indexPath.section==2) { 
    return [self.cellPickerInputArray count]; 
} else { 
    return <some appropriate value>; 
}