Sto usando un UITableView e sto notando che le celle nella mia tableview diventano progressivamente più audaci mentre faccio scorrere, sovrascrive il contenuto e voglio fermarlo ma non riesco a vedere dove sto andando male.Come fermare cella UITableView è sovrascrivere il contenuto?
Sul mio UITableView, per qualche motivo quando faccio scorrere il contenuto della vista tabella si incasina con la UILabel creata manualmente.
Ho bisogno di un UILabel manuale perché ho bisogno di avere celle personalizzate in seguito.
Mentre scorro su e giù, le etichette diventano progressivamente più audaci e più audaci; si sovrappongono sempre e a volte colpiscono anche le righe più in basso (anche prima che siano nella vista).
Se continuo a farlo, il contenuto della cella diventa incomprensibile.
Questo succede solo se il backgroundColor non è impostato come clearColor
.
Ho tentato [cellLabel setClearsContextBeforeDrawing:YES];
e [self.tableView setClearsContextBeforeDrawing:YES];
senza alcun effetto.
Se utilizzo cell.textLabel.text
, il problema sembra scomparire.
Segue un esempio di immagine.
// Simple table view
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
//[self configureCell:cell atIndexPath:indexPath];
NSString *txt = @"Product";
//cell.textLabel.text = txt;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIView *cellView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, cell.frame.size.height)];
UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 120, 35)];
[cellLabel setText:txt];
[cellLabel setFont:[UIFont boldSystemFontOfSize:12]];
[cellLabel setBackgroundColor:[UIColor clearColor]];
[cellView addSubview:cellLabel];
[cellLabel release];
[cell.contentView addSubview:cellView];
[cellView release];
return cell;
}
Image follows;
![image of uitableview][1]
[1]: http://i.stack.imgur.com/5lNy6.png
// Edit to include context
I am using a dictionary to display the contents of the UITableViewCells.
I have attempted to do the following;
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[self configureCell:cell atIndexPath:indexPath];
} // end if
// Configure the cell...
//
// Moved to inside the cell==nil
return cell;
}
-(void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
// Get the txt from the Dictionary/Plist... *removed due verboseness*
UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 120, 35)];
[cellLabel setText:txt];
[cellLabel setFont:[UIFont boldSystemFontOfSize:12]];
[cellLabel setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:cellLabel];
[cellLabel release];
}
questo, anche se risolve il problema di sovrascrittura - causa un problema - rende etichette compaiono ripetutamente in luoghi totalmente casuali - il seguente è solo un esempio, altri campi e le etichette anche ripetono.
vedi foto sotto;
possibile duplicato di [UITableView celle ripetute su scroll] (http: // stackoverflow.it/questions/6844156/uitableview-repeat-cells-on-scroll) –