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'ビューをセルにまっすぐに追加する必要もあります –