2013-04-30 10 views
5

Sto cercando di aggiungere nsindexpath in un array .. sono in grado di aggiungere solo un indexpath .if tento di aggiungere un altro indexpath all'array .. il debugger mostra solo il più nuovo indexpath.Come aggiungere più NSIndexPath in NSMutableArray

for (int i = 0 ; i<[notificationArray count]; i++) 
     { 
      selectedSymptIndexPath = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber]; 
      selectedSympIPArray = [[NSMutableArray alloc]init]; 
      [selectedSympIPArray addObject:selectedSymptIndexPath]; 
     } 

anche se cerco di mettere [selectedSympIPArray addObject:selectedSymptIndexPath]; fuori per il ciclo ancora il suo aggiungendo solo la più recente indexpath piuttosto che mostrare più indexpaths

risposta

8

Nel codice, si alloc ogni volta che in iterazione. È completamente sbagliato. Trova il tuo errore.

È possibile utilizzare questo codice ....

selectedSympIPArray = [NSMutableArray array]; 
for (int i = 0 ; i<[notificationArray count]; i++) 
     { 
      selectedSymptIndexPath = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber];    
      [selectedSympIPArray addObject:selectedSymptIndexPath]; 
     } 
12

Tu sei alloc init'ing l'array ogni volta nel ciclo, non fate che .

Prova questa:

selectedSympIPArray = [[NSMutableArray alloc]init]; 

for (int i = 0 ; i<[notificationArray count]; i++) 
{ 
    selectedSymptIndexPath = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber]; 
    [selectedSympIPArray addObject:selectedSymptIndexPath]; 
} 
+0

@raptor sta funzionando per voi? – satheeshwaran

+0

..solo funziona – raptor

+0

ma quando si scorre uitableview dopo qualche tempo rallenta – raptor

Problemi correlati