Question

I am trying to add nsindexpath into an array .. i am able to add only one indexpath .if i try to add another indexpath into array ..the debugger shows only the newest indexpath .

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

even if i try to put [selectedSympIPArray addObject:selectedSymptIndexPath]; outside for loop still its adding only the newest indexpath rather than showing multiple indexpaths

Was it helpful?

Solution 2

In your code , you alloc every time in iteration. It's totally wrong. Find your mistake.

You can use this code....

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

OTHER TIPS

You are alloc init'ing the array every time in the loop, dont do that.

Try this:

selectedSympIPArray = [[NSMutableArray alloc]init];

for (int i = 0 ; i<[notificationArray count]; i++)
{
   selectedSymptIndexPath = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber];
   [selectedSympIPArray addObject:selectedSymptIndexPath];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top