模态视图中的导航控制器

Jos*_*osa 5 cocoa-touch objective-c ios

目前,当点击按钮时,会出现UIModalPresentationSheet.当它向上滑动时,我想在它的顶部添加一个导航栏.我尝试过很多东西,但似乎没什么用.这是我正在尝试的,它会返回此错误.

    AthleteAdd *addAthlete = [self.storyboard instantiateViewControllerWithIdentifier:@"addAthlete"];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addAthlete];
    //[self.navigationController pushViewController:addAthlete animated:YES];

    addAthlete.delegate = self;
    addAthlete.modalPresentationStyle = UIModalPresentationFormSheet;
  //  UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addAthlete];
    [self presentViewController:navigationController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

但它以模态方式推动它,并且没有modalpresentationsheet形式.如何才能使导航控制器的尺寸正确?

Jor*_*tel 12

尝试更改您的代码,如下所示:

    AthleteAdd *addAthlete = [self.storyboard instantiateViewControllerWithIdentifier:@"addAthlete"];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addAthlete];

    addAthlete.delegate = self;
    navigationController.modalPresentationStyle = UIModalPresentationFormSheet;


    [self presentViewController:navigationController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

因为在这里,你试图自己呈现addAthlete.所以你得到这个错误.