Ahoy!UITableViewCell과 유사한 재사용 가능한 UIView 만들기
UITableViewController에서 사용되는 UITableViewCell 구현과 비슷한 재사용 가능한 UIView (다양한 이유로)를 만들려고합니다. UIScrollView에서 재사용 가능한 뷰를 사용하여 전적으로 달성 할 수없는 무언가를 얻으 려하지 않는다는 것을 알고 싶습니다. 이에서
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//declare cell identifier
static NSString *cellIdentifier = @"cell_identifier";
//dequeue cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
//check cell is valid
if(cell == nil)
{
//create a new cell
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
//
//return cell
return cell;
}
는 셀이 jQuery과 대기열에서 제거되는 것을 주목할 필요가 :
이의 디폴트의 구현입니다. 셀이 유효하지 않으면 새 셀이 만들어집니다. 내 질문은 어떻게이 셀이 나중에 재사용을 위해 "대기"상태가되는 것입니까?
나의 현재 시도 구현은 다음과 같습니다 : 내 TestScrollView에 NSMutableDictionary를 추가하면 cellIdentifier과 TestScrollViewCell (UIView의)를 저장하기 위해 생각하고 사전에 기초하여 그들을 다시 따 버릴
- (TestScrollViewCell *)scrollView:(TestScrollView *)_scrollView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//declare cell identifier
static NSString *cellIdentifier = @"cell_identifier";
//dequeue cell
TestScrollViewCell *cell = (TestScrollViewCell *)[scrollView dequeueReusableCellWithIdentifier:cellIdentifier];
//check cell is valid
if(cell == nil)
{
//create a new cell
cell = [[TestScrollViewCell alloc] initWithFrame:CGRectZero];
}
//
//return cell
return cell;
}
키가 좋은 출발점이 될 것이지만 이것은 실제로 "재사용 가능한"세포의 진정한 구현인가?
내가 볼 수있는 문제는 프레임에 기반하여 배치 된 ScrollView에 UIView를 추가한다는 것입니다. 이런 의미로 뷰를 제거하면 프레임을 수정하여 첫 번째 뷰에 영향을 미치지 않고 뷰를 스크롤 뷰에 추가 할 수 없지만 이것이 섹션 머리글/바닥 글뿐만 아니라 UITableViewCells의 작동 방식이기도합니다.
저는 구현하고자하는 동일한 경로를 따르는 것으로 보이는 this implementation을 보았습니다. 그러나 이것이 재사용 가능한 셀의 실제 구현이라고 100 % 팔리지는 않았습니다.
누구도 이전에이 행운이 있었나요? 나는 이것에 대한 Apple의 주도권을 잡으려고 노력하고있다. 그러나 UITableViewCell과 MKAnnotationView (MapKit) 이외에는 내가 접근 할 수있는 구현이 없다.
도움을 주시면 감사하겠습니다.