I have several tableview and I want the selected values ​​to be displayed in the 3rd tableview .
For this there is an array that collects the answers. But when I push on the controller with the results only the last value is displayed.

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { firstarr = [[NSMutableArray alloc]init]; //array with questions [self.firstarr addObject:[self.data objectAtIndex:indexPath.row]]; //collects the data properly BodyDetailViewController* vc =[[BodyDetailViewController alloc] initWithNibName:@"BodyDetailViewController" bundle:nil]; vc.someArray = firstarr; //some array - ViewController with Results. [self.navigationController pushViewController:vc animated:YES]; } 
  • one
    @ Dmitry99, please use Cyrillic. - VioLet 1:09 pm
  • one
    ok, rewrote - Dmitry99

1 answer 1

In your method, an array is initialized each time.

 firstarr = [[NSMutableArray alloc]init]; //array with questions [self.firstarr addObject:[self.data objectAtIndex:indexPath.row]]; //collects the data properly 

Move the initialization to another place, for example to the method -(void)viewDidLoad

  • Even during initialization, you must use self if you have a retain property. self.firstarr = [NSMutableArray array]; But when adding to the self array it is not necessary to write self. - cyclone