Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Fabio Floris
Fabio Floris
526 Points

Problem With Two NSMutableArray in CellForRowAtIndexPath

Hello everyone I have a problem ... the tutorial Destructive Message helped me understand how to display a list of friends and add them ...

I rather use the checkmark cell I used a button ... To maintain the state of the button (selected or not) I used a NSMutableArray that I display in this way in cellForRowAtIndexPath

       -(UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  {

       static NSString *CellIdentifier = @"cell";
       NPSearchUser_CustomCell *cell = [tableViewFindUser dequeueReusableCellWithIdentifier:CellIdentifier];

      [cell setDelegate:self];
      cell.sendRequestButton.selected = NO;
      cell.tag =  indexPath.row ;

     PFUser *filteredDataObject = [filteredData objectAtIndex:indexPath.row];
     [cell setUserForCell:filteredDataObject];

     if ([contentSelected containsObject:filteredDataObject]) {
         cell.sendRequestButton.selected = YES;

     else {
         cell.sendRequestButton.selected = NO;

So far so good ... now I need to see, through a query that parse.com download the data into a new NSMutableArray, which have received a user request or not.

Viewing this query must be made on the same button with the MutableArray that stores the status of the button.

Entering this:

    if ([self requestInPending: filteredDataObject]) {
        cell.sendRequestButton.selected = YES;

    } else {
        cell.sendRequestButton.selected = NO;


I noticed that my tableview loses the data state of the button and the query to parse ... It does not actually display anything .. I just turned off the button ..

Does anyone know to help me understand how to solve the problem?

I would need to:

The button which sends a friend request takes the state stored in tableview when it is pressed or not pressed.

Also along with this I also need to display (button selected or not) the result of the query that shows which user are selected and then the holders of a friend request in progress.

Surely the problem lies in the fact that I have two MutableArray to do this and then come into conflict with each other and the tableview does not know what to do especially when the cells are reused during scrolling