任何人都可以遇到类似的问题吗? 也许我错过了什么适当的行动?首先尝试在 AppDelegate 中运行此代码,现在位于 ViewController ,并且具有相同的功能..
或者有人知道如何将此代码放入按钮操作中?
也许有人知道,如何使用UIPresentationPopoverController来呈现这个ActionsViewController?
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
ActionsViewController *actionsViewController = [AppLibrary createActionsViewController];
actionsViewController.actionDelegate = self;
actionsViewController.supportedActionTypes = @[[[SupportedAction alloc] initWithActionType:ActionTypeEdit mediaTypes:@[kTypePNG]]];
[actionsViewController setWhitelistedSubTypes:@[@"adjust", @"filter", @"healing"]];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
self.actionsNavigationController = [[UINavigationController alloc] initWithRootViewController:actionsViewController];
[self presentViewController:self.actionsNavigationController animated:YES completion:nil];
}
}
答案 0 :(得分:0)
- Workaround--
只需更改此行:
[self presentViewController:self.actionsNavigationController animated:YES completion:nil];
用这个
UIViewController *rootVC = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
[rootVC presentViewController:self.actionsNavigationController animated:YES completion:nil];
答案 1 :(得分:0)
您正尝试在viewdidappear中显示视图控制器。
尝试延迟运行该部分代码。把你的代码放在这个块中。
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// your code
NewViewController *objNewviewController = [self.storyboard instantiateViewControllerWithIdentifier:@"NewViewController"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:objNewviewController];
navigationController.navigationBar.backgroundColor = [UIColor redColor];
[self presentViewController:navigationController animated:YES completion:nil];
});
如果你想在点击按钮上执行此操作,请使用此
-(IBAction)buttonclick:(id)sender
{
NewViewController *objNewviewController = [self.storyboard instantiateViewControllerWithIdentifier:@"NewViewController"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:objNewviewController];
navigationController.navigationBar.backgroundColor = [UIColor redColor];
[self presentViewController:navigationController animated:YES completion:nil];
}
我检查了代码及其工作正常。如果它不适合你,那么检查你的viewcontroller是否为零?同样适用于您的导航控制器。
答案 2 :(得分:0)
我明白了!:)它与UIPopoverPresentationController和按钮动作一起工作
- (IBAction)popUp:(id)sender {
ActionsViewController *actionsViewController = [AppLibrary createActionsViewController];
actionsViewController.actionDelegate = self;
actionsViewController.supportedActionTypes = @[[[SupportedAction alloc] initWithActionType:ActionTypeEdit mediaTypes:@[kTypePNG]]];
[actionsViewController setWhitelistedSubTypes:@[@"adjust", @"filter", @"healing"]];
// present the controller
if(actionsViewController == nil) {
actionsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"popover"];
}
// present the controller
actionsViewController.preferredContentSize = CGSizeMake(600, 100);
actionsViewController.modalPresentationStyle = UIModalPresentationCustom;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissMe)];
[self.view addGestureRecognizer:tap];
// configure the Popover presentation controller
UIPopoverPresentationController *popoverController = actionsViewController.popoverPresentationController;
popoverController.permittedArrowDirections = UIPopoverArrowDirectionAny;
popoverController.delegate = self;
popoverController.sourceView = self.view;
popoverController.sourceRect =[sender frame];
[self presentViewController:actionsViewController animated:YES completion:nil];
}
- (void)dismissMe {
NSLog(@"Popover was dismissed with internal tap");
[self dismissViewControllerAnimated:YES completion:nil];}
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone; }