1
votes

I am using a UINavigationController to push a UIViewController onto the stack, then when the user selects a row in the table view I allocate a new version of the view controller and push it onto the stack this works fine but then when I start pressing the back button the NSMutableArray that I am using to store the information seems to be keeping the value from the view controller that was just poped from the stack.

Here is the method that is pushing the new onto the stack:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    if (indexPath.section == 1) {
        if (hasLoadedResponses && [responses count] == 0) {
            return;
        }

        VideoDetailViewController_iPhone *nextView = [[VideoDetailViewController_iPhone alloc] initWithNibName:@"VideoDetailViewController_iPhone" bundle:nil withVideoArray:[responses objectAtIndex:indexPath.row]];
        nextView.navController = navController;
        [navController pushViewController:nextView animated:YES];
        [nextView release];
    }

}

I'm sure there is something stupid I am missing, but can't seem to find it right now.

1
How does VideoDetailViewController_iPhone interact with the NSMutableArray? That's probably where your problem is. - yuji
And, how and where is the mutable array defined? If it's a class variable rather than a property, that could be the issue. - picciano

1 Answers

0
votes

Assuming the mutable array is [responses objectAtIndex:indexPath.row] because is the only value you pass to the new pushed view controller, then if you are modifying it in you have to take in account that is the same object and so modifications are shared.

You can write:

. withVideoArray:[NSMutableArray arrayWithArray:[responses objectAtIndex:indexPath.row]];

As I said, I assume that object is the mutable array of your problem.

Another smarter solution is defining the property you use to store the mutable array as 'copy' instead of 'retain'.