I have few table view controllers and I want selections from them to be shown on “ResultTableViewController”. I also have array that collects the selected data and when i finally push it to the “ResultViewController” it shows only the last selection. Please help
- (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];
}
You have to remove this line :
Because you’re initializing your NSMutableArray each time you’re selecting a cell, so all the data previously stored is erased and
vc.someArrayis getting an array with only your last selection, that’s why 😉Init your NSMutableArray outside the method, in your
viewDidLoadfor example