UITableView의 첫 번째 행에 일부 UILabels를 삽입하려고하지만 예상치 못한 결과가 발생합니다. 간결함을 위해, 여기에 요약입니다 :UITableView의 0 행 사용자 정의
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString* identifier = @"cell";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
cell = [[UITableViewCell alloc[ .....
cell.textLabel.text = @"";
if (indexPath.row == 0) {
cell.backgroundColor = ....
UILabel* x = .....
[x setTag:1];
[cell insertSubview:x];
}
else {
cell.textLabel.text = ....
for (UIView* view in cell.subviews) {
if (view.tag == 1)
[view removeFromSuperview];
}
}
return cell
} 어쨌든 요점을의
. 문제는 배경색이 올바르게 설정되어있는 동안 테이블보기를 스크롤 할 때마다 내가 삽입 한 커스텀 UILabel이 사라진다는 것입니다. 아마도 dequeueReusableCellWithIdentifier에 대한 오해에서 비롯된 것일 수도 있지만 관계없이 라벨이 다시 삽입 될 것입니다.
를 사용 : cellForRowAtIndexPath를'대부분의 작동 시간, 그것을하는 * 공식 * 방법은 ['-tableView : willDisplayCell : forRowAtIndexPath :'] (http://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference)에 있습니다. .html # // apple_ref/occ/intfm/UITableViewDelegate/tableView : willDisplayCell : forRowAtIndexPath :). –
'insertSubview'? 코드의 예일 뿐이지 만 정확하기 만하면됩니다. 실제 코드를 복사하여 붙여 넣기 만하면 정확한 결과를 볼 수 있습니다. 또한 셀의 'contentView' 뷰를 셀에 직접 추가하지 않아야합니다. –