2015-08-02 2 views
4

Je l'ai lu vue de la table et il est l'édition de styles mais j'ai quelques problèmes car il n'y a que trois style de montage comme suit:Table Réorganiser cellule de vue sans le bouton supprimer et mettre en œuvre swipe pour supprimer des lignes

  1. UITableViewCellEditingStyleNone
  2. UITableViewCellEditingStyleDelete
  3. UITableViewCellEditingStyleInsert

Je veux avoir réordonner les cellules Tableview que j'implémentés en utilisant avec succès est délégués.

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ 
    return YES; 
} 

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    return UITableViewCellEditingStyleNone; 
} 
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ 
    //handle the editing style 
} 
-(NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath{ 
    //move cells 
} 
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{ 
    return YES; 
} 

Je ne veux pas utiliser UITableViewCellEditingStyleDelete car il montre un bouton circulaire rouge sur la vue de la table. Au lieu de cela, je veux glisser-à-supprimer et la fonctionnalité de réorganisation ensemble.

Y a-t-il un moyen de l'implémenter?

+0

Avez-vous fait cela. Je dois faire la même chose –

+0

@ParulGarg désolé pour la réponse tardive. Oui, s'il vous plaît vérifier ceci: http://stackoverflow.com/questions/31802088/reorder-tableview-cell-with-a-custom-button – Niloufar

+0

Pour info un cookie futé a figuré un travail autour de cela http: // stackoverflow. com/questions/6097464/reordering-controls-on-uitableview-while-not-in-editing-mode/33182901 # 33182901 – Tys

Répondre

1

Cela peut être fait mais avec les conditions suivantes. Le balayage vers l'effacement ne fonctionnera que lorsque la vue de la table est et non en mode édition et le réordonnancement de la table ne fonctionnera que lorsque la vue de la table est en mode édition. Vous ne pourrez pas effectuer un balayage par effacement en même temps que le réapprovisionnement de la table.

Pour faire ce travail que vous avez besoin:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Only allow deletion when the table isn't being edited 
    return tableView.isEditing ? UITableViewCellEditingStyleNone : UITableViewCellEditingStyleDelete; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    // handle the row deletion 
} 

- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath { 
    // Check if move is valid 
    return proposedDestinationIndexPath; 
} 

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 

- (void)tableView:(UITableView * nonnull)tableView moveRowAtIndexPath:(NSIndexPath * nonnull)fromIndexPath toIndexPath:(NSIndexPath * nonnull)toIndexPath { 
    // process the moved row 
} 

Vous aurez besoin du bouton standard Edition dans la barre de navigation (ou d'une autre manière pour activer le mode d'édition de la table). Une façon courante de faire est d'ajouter la ligne suivante à l'intérieur de votre viewDidLoad vue tableau de commande Méthode:

self.navigationItem.rightBarButtonItem = [self editButtonItem]; 
+0

Merci pour votre réponse, mais iTunes a cette fonctionnalité, donc je suppose qu'il devrait être disponible pour nous aussi. – Niloufar

+0

iTunes est sur votre Mac, pas sur votre appareil iOS. S'il vous plaît clarifier ce que vous voulez dire. – rmaddy

+0

Je veux dire Apple Musique sur iOS 8.4 a cette capacité – Niloufar