weird behaviour ModalViewController
I have a view controller (AddCommentViewController) that can save comments offline and edit comments when saved offline.
When I load the AddCommentViewController in the view where I want to add a new comment and save it offline, there is开发者_StackOverflow社区 no problem:
AddCommentViewController *addView = [AddCommentViewController new];
[addView setTitle:@"New Comment"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addView];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
[delegate.navigationController presentModalViewController:navController animated:YES];
[delegate dismissPopOver:self animated:YES];
[navController release];
[addView release];
No problem here, the view is animated nicely from the bottom. And when dismissed it is animated nicely to the bottom.
But now the problem.
In an other view I can see a list of all the comments saved offline. when I load the AddCommentViewController here something weird happens.
When I try to present the view modal it is animated from the left, stops at a weird location (not centred but a but to the buttom-right). and when I dismiss it, the view is animated back to the left side and my other view is orientated to portrait. I can't seem to find the problem and the code is almost identical:
Comment *comment = [allComments objectAtIndex:indexPath.row];
AddCommentViewController *addView = [[AddCommentViewController alloc] initWithId:comment.identifier];
[addView setTitle:@"Change comment"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addView];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
navController.navigationBar.tintColor = [UIColor P4aPurple];
[self presentModalViewController:navController animated:YES];
[navController release];
[addView release];
I tried to force the view at a specific orientation with:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
but I get this error:
The view controller <UISplitViewController: 0x1843d0> returned NO from -shouldAutorotateToInterfaceOrientation: for all interface orientations. It should support at least one orientation.
If I hold the device in portrait when I load an offline commend its working correct.
If you want to force Portrait orientation, try this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
return YES;
else return NO;
}
FIXED, it turns out that the view has to be presented modal in the split view controller and not in the detail view controller of the split view.
精彩评论