2016-03-01 1 views
1

J'ai une sous-classe de UITableViewCell appelée ReminderCell.Cellule personnalisée de retour de UITableViewCell

ReminderCell a une méthode appelée backToPlaceAnimation que j'ai écrite.

Le problème est par exemple si je veux appeler backToPlaceAnimation le premier ReminderCell de RemindersVC en utilisant tableView: cellForRowAtIndexPath: il ne revient pas l'objet correct (il est l'objet UITableViewCell et non ReminderCell du tout).

Comment puis-je obtenir l'objet correct?

code:

NSIndexPath *cellIndexPath=[NSIndexPath indexPathWithIndex:0]; 

ReminderCell *cell=(ReminderCell*)[self tableView:self.AroundersTableView cellForRowAtIndexPath:cellIndexPath]; 

[cell cancelDeletion]; 

journal Crash:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid index path for use with UITableView. Index paths passed to table view must contain exactly two indices specifying the section and row. Please use the category on NSIndexPath in UITableView.h if possible.

cellForRowAtIndexPath: override:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //Creating a default cell using "cellIdentifier"(NSString) 
    ReminderCell *cell=[tableView dequeueReusableCellWithIdentifier:@"Cell"]; 
    if (cell==nil) { 
     cell=[[ReminderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; 
    } 
    //Changing "cell"'s "index" to indexPath.row 
    cell.index=(int)indexPath.row; //Crashes here 

    [email protected]"Hello"; 

    //Returning cell 
    return cell; 
} 

Merci!

+0

Afficher un code sur la façon dont vous obtenez les cellules de 'cellForRowAtIndexPath' –

+0

Êtes-vous. –

+0

@DantePuglisi Mis à jour le message, s'il vous plaît jeter un oeil –

Répondre

1

Vous devez remplacer [NSIndexPath indexPathWithIndex:0]; avec [NSIndexPath indexPathWithIndex:0 inSection:0];

0

Vous déclarez cell comme UITableViewCell, déclarer comme ReminderCell si vous voulez qu'il soit ce type

+0

Toujours le même problème, mis à jour le poste s'il vous plaît jeter un oeil –

0

définir votre cellule ReminderCell

ReminderCell *cell = [self.AroundersTableView cellForRowAtIndexPath:cellIndexPath]; 
+0

mis à jour, maintenant vous devriez être en mesure d'appeler [cell cancelDeletion]; – gvuksic

+0

Toujours le même problème, mis à jour le poste s'il vous plaît jeter un oeil –

+0

est l'indice dans ReminderCell défini comme Indexpath? vous n'envoyez qu'une seule valeur, indexpath est constitué de deux valeurs – gvuksic

0

Votre cellForRowAtIndexPath devrait retourner ReminderCell au lieu de UITableViewCell

Donc, il devrait commencer par ceci:

-(ReminderCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
+0

Je ne peux pas changer le 'cellForRowAtIndexPath', c'est une fonction de délégué –

+0

Oui, vous pouvez, je l'ai fait beaucoup de fois.Vous renvoyez toujours un UITableViewCell, juste une sous-classe de celui-ci –

0

D'après l'erreur que vous avez montrée ci-dessus, vous ne récupérez pas la cellule de la cellule pour la méthode de ligne car le chemin d'index que vous créez est incorrect. Essayez d'utiliser [NSIndexPath indexPathForRow:0 inSection:0] (Remarque: vous devez changer les 0. pour refléter la cellule que vous voulez