I have a requirement to remove a previous view controller in a stack. I have successfully used this method in the past, without any problems:
NSMutableArray *vcs = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
BOOL removedFlag = YES;
while (removedFlag == YES)
{
removedFlag = NO;
for (UIViewController *vc in vcs)
{
if( ![vc isKindOfClass:[self class]] && ![vc isKindOfClass:[MenuVC class]] )
{
[vcs removeObject:vc];
removedFlag = YES;
break;
}
}
}
[self.navigationController setViewControllers:[NSArray arrayWithArray:vcs]];
Now I’m updating the app, and it mysteriously crashes on release configuration, not on debug. In addition, there are no warnings whatsoever in debug mode. I think something changed with the SDK. It never did this before.
I’ve made a sample project available:
http://dl.dropbox.com/u/7834263/RemoveTest.zip
This is an ARC-enabled project.
The first line should actually be:
NSMutableArray is a subclass of NSArray.
arrayWithArrayis a method of the NSArray class — it creates an immutable array. ThemutableCopymethod creates a mutable copy of the original array. You never really should have been able to callremoveObjecton your vcs array because it was never actually an NSMutableArray — it was an NSArray.