Can you please help me to find reason why my app crashes after clicking on segmented control? Not allways, but usualy after some clicks.
Error message:
I think the problem is in these line of code
for (NSString *file in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL])
{
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
}
and you are using it in two methods didLoad and didUnload. The reason that you are getting because you are updating the content of the following array
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL]
When you go thorough enumerator class you will get this caution of "not updating the content while enumerator is in use" ... So to overcome this problem simply do following to all the places where you have used this code....
NSArray* temp = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
for (NSString *file in temp)
{
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
}
i hope this would solve your problem...