简体   繁体   中英

UIViewController presented modally show up shifted to the top

I'm presenting a UIViewController with presentModalViewController:animated.

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

However the top bar is not visible, and it is seems shifter to the top (there is an empty space on the bottom).

This is viewDidLoad in which I set the Close button on the navigationItem

- (void)viewDidLoad
{
    [super viewDidLoad];

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

thanks

如果您使用的是iPhone,请删除

[import setModalPresentationStyle:UIModalPresentationFormSheet];

You should add a navigation bar and then present 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];

hope this helps. happy coding :)

When you add a UIBarButtonItem, the NavigationController is nil, and navigationBar is nil also. So it doesn't work with navigationItem.

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

You should add a NavigationController for the import object, and present it.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM