Picker가 포함 된 사용자 지정 UITableViewCell 클래스가 있습니다. 셀과 그 내용은 핵심 데이터 엔티티로 채워집니다. 이 사용자 정의 셀은 둘 이상의보기 컨트롤러에서 볼 수 있으므로 구조, 데이터 소스 및 위임 메소드를 처리해야하는 유틸리티 클래스가 있습니다.UIVIewController, 사용자 지정 UITableViewCell 및 유틸리티 클래스 간의 UIPickerView 데이터 소스 관리
셀프 데이터 소스를 설정할 때 셀이 제대로 표시 될 때처럼 뭔가 빠져있는 것처럼 보입니다. Utility 클래스로 설정하면 numberOfComponentsInPickerView:
메서드 만 호출되고 (lldb)를 제외한 로그에는 아무 것도 나타나지 않으면 응용 프로그램이 충돌합니다. 내 코드 샘플에서는 하나의 구성 요소와 제목이 "Test"인 간단한 행을 가진 간단한 선택 도구를 만들 것입니다.
ViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PickerCell *pCell = nil;
Picker *picker = [self.array objectAtIndex:indexPath.row];
UtilityCustomCells *cellUtility = [[UtilityCustomCells alloc]init];
pCell = [cellUtility createPickerCell:tableView withReuseIdentifier:kPickerCellRID andPicker:picker];
pCell.picker.delegate = cellUtility; //does not work
pCell.picker.dataSource = cellUtility; //does not work
/* This works
pCell.picker.delegate = self;
pCell.picker.dataSource = self;
*/
return pCell;
}
}
마지막
utilityCustomCells.h
#import "PickerCell.h"
#import "Picker.h"
@protocol CustomCellUtilityDelegate <NSObject,UIPickerViewDataSource,UIPickerViewDelegate>
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
@end
에서
:UtilityCustomCells.m
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
NSLog(@"Here1");
return 1;
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
NSLog(@"Here2");
return 1;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSLog(@"Here3");
NSString *title = @"Test";
return title;
}
만에 다시 반복 처리는, 단지 "Here2는"로그에 인쇄됩니다. 모든 조언을 많이 주시면 감사하겠습니다. 미리 감사드립니다!