유용한 지침에 따라 xib 파일에서 사용자 정의 UITableViewCell
을로드했습니다. How do you load custom UITableViewCells from xib files.cellForRowAtIndexPath의 다른 UITableViewCell 유형을 반환하십시오.
내 UITableView
의 첫 번째 행에 대해서만이 사용자 정의 셀을 원한다. 나머지는 간단한 레이블이고 표준은 UITableViewCell
이다.
문제는 사용자 정의 셀을 포함하면 전체 UITableView
이 표시되지 않고 탐색 요소를 제외하고 화면이 비어있는 것입니다. 표준 셀을 사용하면 표가 잘 나타나므로 사용자 정의 셀과 관련이 있습니다.
여기에 셀을 반환해야하는 코드가 있습니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == 0) {
ArticleDetailCell *cell = (ArticleDetailCell *)[tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"%@Detail", reuseIdentifier]];
if(!cell) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ArticleDetailCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = (ArticleDetailCell *)[topLevelObjects objectAtIndex:0];
}
[[(ArticleDetailCell *)cell judges] setText:[[self caseBaseArticle] judges]];
[[(ArticleDetailCell *)cell judgementDate] setText:[[self caseBaseArticle] judgmentDate]];
[[(ArticleDetailCell *)cell court] setText:[[self caseBaseArticle] court]];
return cell;
} else {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if(!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier] autorelease];
[[cell textLabel] setNumberOfLines:1];
[[cell textLabel] setFont:[UIFont systemFontOfSize:14]];
[[cell textLabel] setText:articleRowTitles[indexPath.row-1]];
}
if ([self tableRowHasContentDetail:indexPath]) {
[self enableTableCell:&cell];
}else {
[self disableTableCell:&cell];
}
return cell;
}
}
ArticleDetailCell은 XIB 파일에서 확인로드와 속성 내가 디버거에서 볼 수 올바르게 설정하세요. 내가 (gdb)
에서 사용자 정의 셀 객체를 인쇄 할 때 return cell
에서 멈춤.
<ArticleDetailCell: 0x4bc22b0; baseClass = UITableViewCell; frame = (0 0; 320 367); autoresize = W+TM+BM; layer = <CALayer: 0x4bc23c0>>
세포 역 참조에는 어떤 문제가 있습니까? 나는 여전히 카운트를 유지할 때와 카운트가 증가하거나 증가하지 않을 때 내 머리를 터뜨릴 것입니다.
단일 셀에 문제가있어서 전체 UITableView가 사라지는 이유는 무엇입니까?
편집 :은 참고 @BoltClock
- (void)disableTableCell:(UITableViewCell **)cell {
[*cell setAccessoryType:UITableViewCellAccessoryNone];
[*cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[[*cell textLabel] setTextColor:[UIColor lightGrayColor]];
}
그냥 급히 : 당신의 당신이 당신의 라벨을 사용자 정의 할 때, 당신은 당신이 이미 선언하고'ArticleDetailCell'로 초기화하기 때문에 ArticleDetailCell' 때마다'에'cell' 캐스팅하지 않아도 문합니다. 'enableTableCell :'과'disableTableCell :'메소드는 어떻게 생겼을까요? – BoltClock
@BoltClock은 리팩터링 힌트를 주셔서 감사합니다. 이전에 UITableViewCell로만 사용자 정의 셀을 생성하는 문제를 해결했습니다. –
@BoltClock은 disableTableCell 메소드를 질문에 추가했습니다 (활성화는 거의 같지만 다른 값을 사용함). –