2015-12-18 32 views
-3

任何人都可以遇到類似的問題嗎? 也許我錯過了什麼適當的行動?首先嚐試在的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

警告:試圖提出在<視圖控制器:>誰的觀點是不是在窗口層次! – alideny

+1

請編輯代碼以使其更具可讀性 – Gihan

+0

'who'是self.actionsNavigationController? – arturdev

回答

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; } 
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]; 
+0

我已啓動,但在我的設備上出現黑屏並出現此錯誤:應用程序嘗試將nil視圖控制器推向目標 alideny

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是否爲零?對於您的導航控制器也一樣。

+0

沒有幫助(( – alideny

+0

)它是否給您提供錯誤或無所作爲? – Wolverine

+0

'NSInvalidArgumentException',原因:'*** - [__ NSPlaceholderDictionary initWit hObjects:forKeys:count:]:嘗試從對象[0]' – alideny