2009-08-31 12 views

答えて

3

我々は実行時にセルを追加した場合、私は同じ細胞を用いて出力を受けています。.. UIテーブルビュー

+0

だけで編集モード中にそれをやって注意してください。 – Amagrammer

0

[OK]を[のtableView reloadData]メソッドを使用します..しかし..私たちは、このためのソリューションを必要とします

[mytableview.contentView clearsContextBeforeDrawing]; 
24

クリアデータRを呼び出す前に:あなたは、細胞が前

例サブビューを追加クリアでき

のUITableViewの最初と最後のセル.. eloadDataを呼び出すと、ユーザーはテーブルがクリアされ、新しいデータで再入力されたことを確認できます。

myArray = nil; 
[myTableView reloadData]; 
0

あなたは再利用し、セルの値で、その同じではない場合は見ることができます - それを再作成します。

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
MyLog(@"Start Table: cellForRowAtIndexPath: %d", indexPath.row); 

NSString *MyIdentifier = [NSString stringWithFormat:@"MyIdentifier %i", indexPath.row]; 
UILabel *lblNew; 
lblNew = [UILabel new]; 
UILabel *lblCell; 
lblCell = [UILabel new]; 

MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

if (cell == nil) 
{ 
    cell = [[[MyTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; 
    [cell.contentView addSubview:[lblNameArray objectAtIndex:indexPath.row]];  
} 
else 
{ 
    lblNew = [lblNameArray objectAtIndex:indexPath.row]; 
    for (id label in [cell.contentView subviews]) 
    { 
     if ([label isKindOfClass:[UILabel class]]) 
     { 
      lblCell = label; 
     } 
    } 
    if (![lblNew.text isEqualToString:lblCell.text]) 
    { 
     cell = [[[MyTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; 
     [cell.contentView addSubview:[lblNameArray objectAtIndex:indexPath.row]]; 
    } 
} 
return cell; 
2

これは私の周りの仕事でした。 set cell = nil;

static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
cell = nil; 
-1

スクロール後に選択項目が2重になりました。今、ディスプレイは期待通りにクリーンです! は(ところで回避策

static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
cell = nil; 

とを使用しました。私は、セルの選択に関するより正確な反応の印象を持ってclearsContextBeforeDrawingがそれをスタンドアロンとしてシミュレータで

[cell.contentView clearsContextBeforeDrawing]; 

を動作しませんでした ありがとう

1

ところで、clearsContextBeforeDrawingは財産であり、

[cell.contentView clearsContextBeforeDrawing]; 

は、その値を返す以外は何もしません。

0

スウィフト:それが最善の方法かではありません、しかし、私はクリアするには、このコードを使用してデータをroloadよわからない:

fileprivate func clearTable() { 
    self.tableviewData.removeAll(keepingCapacity: false) 
    self.tableView.reloadData() 
}