I have a view with a tab bar and a table view in it. At a certain point I call a modal view, and when I dismiss it, the original view seems to stretch or shift down, as the background image is lower and the table view is longer to the point that the last cell goes outside of the frame.
I call the modal view from tableView:didSelectRowAtIndexPath:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableDictionary *row = [[[[self.productDetails valueForKey:@"sections"] objectAtIndex:indexPath.section] valueForKey:@"rows"] objectAtIndex:indexPath.row];
NSMutableDictionary *post = [self.productDetails valueForKey:@"post"];
if ([[row valueForKey:@"type"] isEqualToString:@"pick"])
{
self.xPicker = nil;
self.xPicker.options = nil;
self.pickerOptions = nil;
self.xPicker = [[[TablePicker alloc] initWithNibName:@"TablePicker" bundle:[NSBundle mainBundle]] autorelease];
NSMutableDictionary *newPicker = [[[NSMutableDictionary alloc] init] autorelease];
[newPicker setValue:[NSString stringWithFormat:@"%d", indexPath.section] forKey:@"section"];
[newPicker setValue:[NSString stringWithFormat:@"%d", indexPath.row] forKey:@"row"];
[newPicker setValue:[row valueForKey:@"options"] forKey:@"options"];
[newPicker setValue:[row valueForKey:@"value"] forKey:@"value"];
self.xPicker.options = [NSMutableDictionary dictionaryWithDictionary:newPicker];
self.pickerOptions = [NSDictionary dictionaryWithDictionary:newPicker];
self.xPicker.view.frame = self.view.bounds;
[self presentModalViewController:self.xPicker animated:YES];
}
}
Inside the modal view controller, I do some stuff, then fire a notification to let the parent controller know that it’s ok to dismiss it. This part doesn’t feel right, but I was getting an error occassionally when I had the modal view call:
[self.parentViewController dismissModalViewControllerAnimated:YES];
Anyways, the code block where I dismiss the modal view is as follows:
- (void) reloadCell
{
[self dismissModalViewControllerAnimated:YES];
if (self.xPicker.choice != nil)
{
NSDictionary *choice = self.xPicker.choice;
NSMutableDictionary *row = [[[[self.productDetails valueForKey:@"sections"] objectAtIndex:[[choice valueForKey:@"section"] intValue]] valueForKey:@"rows"] objectAtIndex:[[choice valueForKey:@"row"] intValue]];
[row setObject:[choice valueForKey:@"value"] forKey:@"value"];
[[self.productDetails valueForKey:@"post"] setObject:[choice valueForKey:@"value"] forKey:[row valueForKey:@"key"]];
Request *xReq = [[[Request alloc] init] autorelease];
[NSThread detachNewThreadSelector:@selector(updateOrderFromProductDetails:) toTarget:xReq withObject:[self.productDetails valueForKey:@"post"]];
self.xPicker = nil;
}
}
I don’t know if it’s related, but I found it interesting that when I present this modal controller while the device is in landscape mode, the view goes wonky.
Does anyone know how to fix this?
Edit: After some searching, it appears that both problems are related and have to do with my current view controller being a subview of another view controller, but not through a navigation controller.
As I understand it, my decision to not use a nav controller is confusing my view stack somehow. I had a feeling that would come back to bite me in the butt.
Unfortunately, I can’t seem to find a solution to my problem anywhere.
Ok, I have one solution to this problem.
Instead of having my current view controller call
presentModalViewController, I call it from the appDelegatetabBarControllerlike so:This still feels a bit hacky, but it solves both problems of
1) resizing when the modal view is dismissed
2) the modal view being unable to pop up in landscape mode
I hope this can help someone else out there in this cruel Apple world.