奇怪的行为ModalViewController

时间:2011-09-16 13:33:34

标签: iphone objective-c ios ipad modalviewcontroller

我有一个视图控制器(AddCommentViewController),可以离线保存评论并在离线保存时编辑评论。

当我在视图中加载AddCommentViewController时,我想要添加新注释并将其保存为脱机,这是没有问题的:

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];

这里没问题,视图从底部很好地动画。当被解雇时,它很好地动画到底部。

但现在问题。

在另一个视图中,我可以看到离线保存的所有评论的列表。当我在这里加载AddCommentViewController时会发生一些奇怪的事情。

当我尝试呈现视图模态时,它从左侧动画,停在一个奇怪的位置(不是居中但是一个但是到了按钮右侧)。当我解雇它时,视图回到左侧,我的另一个视图朝向肖像。 我似乎无法找到问题,代码几乎完全相同:

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];

我尝试使用以下方式强制执行特定方向的视图:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

但是我收到了这个错误:

The view controller <UISplitViewController: 0x1843d0> returned NO from -shouldAutorotateToInterfaceOrientation: for all interface orientations. It should support at least one orientation.

如果我在加载离线状态时将设备保持在纵向状态,请说明其工作正常。

2 个答案:

答案 0 :(得分:0)

如果您想强制纵向方向,请尝试以下方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
        return YES;
    else return NO;
}

答案 1 :(得分:0)

FIXED,事实证明视图必须在拆分视图控制器中以模态显示,而不是在拆分视图的详细视图控制器中显示。