2009-08-31 9 views

risposta

3

uso [tableView reloadData] metodo su vista tabella ui

+0

Basta essere attenti a farlo mentre in modalità Modifica. – Amagrammer

0

ok .. ma .. abbiamo bisogno di soluzione per questo .. se aggiungiamo le cellule in fase di esecuzione, ho ricevuto l'uscita con le stesse cellule in prima e l'ultima cellule del UITableView ..

è possibile cancellare la cella prima di aggiungere qualsiasi subviews

Esempio:

[mytableview.contentView clearsContextBeforeDrawing]; 
24

Cancellare tutti i dati prima di chiamare r eloadData, e ora l'utente vedrà la tabella essere cancellata e ri-popolata con nuovi dati.

myArray = nil; 
[myTableView reloadData]; 
0

È possibile esaminare il valore della cella riutilizzata e se non è la stessa, quindi ricrearlo.

(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

Questo era il mio giro attorno al quale funzionava. set cell = nil;

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

Ho avuto doppie voci sulla selezione dopo lo scorrimento. Ora il display è pulito come previsto! Usato la soluzione

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

e anche (btw:. ClearsContextBeforeDrawing come standalone non ha funzionato

[cell.contentView clearsContextBeforeDrawing]; 

nel simulatore ho l'impressione di reazione più accurata sulla selezione delle cellule Grazie

!
1

A proposito, clearsContextBeforeDrawing è una proprietà e

[cell.contentView clearsContextBeforeDrawing]; 

non fa altro che restituire il suo valore.

0

Swift: Non sono sicuro che sia il modo migliore o no, ma io sto usando questo codice per cancellare e roload dati:

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