0

我正在展示一个带有 presentModalViewController:animated 的 UIViewController。

    CMImportViewControlleriPhone *import = [[CMImportViewControlleriPhone alloc] initWithNibName:@"Import-iPhone" bundle:nil];
    [import setModalPresentationStyle:UIModalPresentationFormSheet];
    [import setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self presentModalViewController:import animated:YES];
    [import release];

然而,顶部栏是不可见的,并且它似乎移到顶部(底部有一个空白区域)。

这是 viewDidLoad,我在其中设置了 navigationItem 上的 Close 按钮

- (void)viewDidLoad
{
    [super viewDidLoad];

    closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStyleBordered target:self action:@selector(closeButtonPushed:)];
    [[self navigationItem] setRightBarButtonItem:closeButton];
    [closeButton release];
}

谢谢

4

3 回答 3

0

如果您正在使用 iPhone 删除

[import setModalPresentationStyle:UIModalPresentationFormSheet];
于 2012-09-11T09:20:42.467 回答
0

您应该添加一个导航栏,然后呈现 modalView

CMImportViewControlleriPhone *obj = [[CMImportViewControlleriPhone alloc] initWithNibName:@"Import-iPhone" bundle:nil];
[obj setDelegate:self];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:obj];
[self presentModalViewController:navigationController animated:YES];
[obj release];
[navigationController release];

希望这可以帮助。快乐编码:)

于 2012-09-11T09:28:13.097 回答
0

添加 UIBarButtonItem 时,NavigationController 为 nil,navigationBar 也为 nil。所以它不适用于navigationItem。

closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStyleBordered target:self action:@selector(closeButtonPushed:)];
[[self navigationItem] setRightBarButtonItem:closeButton];

您应该为导入对象添加一个 NavigationController 并呈现它。

CMImportViewControlleriPhone *import = [[CMImportViewControlleriPhone alloc] initWithNibName:@"Import-iPhone" bundle:nil];
[import setModalPresentationStyle:UIModalPresentationFormSheet];
[import setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:import];
[self presentModalViewController:import animated:YES];
[import release];
[nc release];
于 2012-09-11T09:56:47.117 回答