2013-08-13 8 views
6

Desidero utilizzare l'opzione "scorri per eliminare" nel mio progetto.Scorri per eliminare l'opzione nei problemi di UITableView

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     NSDictionary *userData = [_contactsArray objectAtIndex:indexPath.row]; 
     NSLog(@"delete row %@",userData); 
    } 
} 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    return YES; 
} 

Sto usando questo codice ma fornisce l'output seguente che non desidero. enter image description here

Non voglio quella parte sinistra segno meno sulla cella. Voglio solo scorrere e mostrare il pulsante Elimina. Lo stesso codice che ho usato nel mio progetto precedente e funziona bene (basta scorrere per mostrare il pulsante Elimina, nessun segno meno sul lato sinistro)

Per favore aiutatemi a risolvere questo.

+0

http://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableViewCell/shouldIndentWhileEditing – Kevin

+0

http://stackoverflow.com/questions/3020922/is-there-any-way-to-hide-delete-button-while-editing-uitableview – Rushabh

+0

Stai sovrascrivendo i metodi UITableViewDelegate corretti. Ma stai impostando la proprietà 'editing' del tuo UITableView su 'YES' in qualsiasi punto del tuo codice? Se è così, ciò farà sì che i segni meno rossi siano visibili. – hgwhittle

risposta

9

Stai ignorando i metodi di delega corretti per la funzionalità "scorri per eliminare". Per quanto riguarda i segni meno:

Nascondi segno meno in questo modo:

self.yourTableView.editing = NO; 
//or simply remove this line of code altogether because this property is NO by default 

Visualizza segno meno in questo modo:

self.yourTableView.editing = YES; 
1

Prova questa:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
     // Return YES if you want the specified item to be editable. 
     return YES; 
    } 

    // Override to support editing the table view. 
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
     if (editingStyle == UITableViewCellEditingStyleDelete) { 
      //add code here for when you hit delete 
     }  
    } 
0

Suona come si sta girando la bandiera tableView.editing su così le file si presentano con il segno meno. prova a cercare self.tableView.editing = YES; e fallo NO o semplicemente commenta quella linea.

3

Innanzitutto creare la tua vista tabella e impostare il metodo delegato e origine dati a questo.

self.contacts=[[UITable alloc]init]; 
    self.contacts.dataSource=self; 
    self.contacts.delegate=self; 
    self.contacts.userInteractionEnabled=YES; 
    //self.contacts.editing = YES; 
    [self.view addSubview:self.contacts]; 

E poi sovrascrivere i metodi delegato e origine dati, per eliminare ignorare i seguenti metodi.

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
     // Return YES if you want the specified item to be editable. 
     return YES; 
    } 

    // Override to support editing the table view. 
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
     if (editingStyle == UITableViewCellEditingStyleDelete) { 
      //add code here for when you hit delete 
     }  
    } 

Per segno meno sul lato sinistro uso self.contacts.editing = YES; Nel mio caso non voglio questo segno meno così semplicemente non usare quella proprietà o impostare self.contacts.editing = NO;

si hw731 Grazie per avermelo ricordato questa proprietà, ho sprecato la mia mezza giornata su questo.

Problemi correlati