I have a loop for checking if a file extension is on an array:
NSArray* validExtensions = [NSArray arrayWithObjects:@"jpg", @"jpeg", @"png", @"gif", nil];
for (NSString *ext in validExtensions) {
NSLog(@"filePath: %@\n extension:%@", ext, filePath.pathExtension);
if ([ext isEqualToString:[self.filePath pathExtension]]) {
PhotoDetailView *detView = [[PhotoDetailView alloc] initWithNibName:@"PhotoDetailView" bundle:nil];
detView.image = [UIImage imageWithContentsOfFile:self.filePath];
[self.navigationController pushViewController:detView animated:YES];
} else {
DetailView *theDetail = [[DetailView alloc] initWithNibName:@"DetailView" bundle:nil];
theDetail.title = self.fileName;
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"My Files" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease];
theDetail.textString = self.filePath;
[self.navigationController pushViewController:theDetail animated:YES];
}
}
For some reason, if after the if and else i put break; it just matches jpg entry in the array. If I remove it, I get odd things about nested animations in the log, and multiple views get pushed:
- Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
- Unbalanced calls to begin/end appearance transitions for .
- nested push animation can result in corrupted navigation bar
What am I doing wrong?
I’m not sure what you expected when using the
breakinside aforloop, except that it should break the loop (exit without continuing on to the next item). So … the first time through is with your first element (@”jpg”), where it does something then stops.Also, your code doesn’t do at all what you said it’s doing. You said, “I have a loop for checking if a file extension is on an array” but your code actually creates an array of file extensions and tries to perform navigation for each one.
Unless I’ve missed your point, I don’t think you want a for loop. I think you want to get your extension from wherever you need it (some chosen file name?), then just ask the validExtensions array if it contains your file’s extension:
The key difference is you’re now asking the array if it contains an object (extension) versus looping the array, locating a match, and trying to break there. That’s your design error.
Your bug (what’s triggering multiple navigations and their associated log entries) is in the fact that you’re hitting every single valid extension, navigating to either the photo detail view if it matches your file extension, or your “My Files” view if not … and you’re doing this for every entry in the valid extensions array, resulting in four navigations.
If I’ve not gotten it right, please update your question to clarify your overall goal.