如何将此 Objective-C 代码放入按钮操作中?

Posted

技术标签:

【中文标题】如何将此 Objective-C 代码放入按钮操作中?【英文标题】:How to put this Objective-C code in the button action? 【发布时间】:2015-12-22 05:51:33 【问题描述】:
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];

【问题讨论】:

- (IBAction)go:(id)sender ; 如何从按钮调用此代码? 这可能会有所帮助:***.com/questions/5843427/…。在按钮事件中,您可以粘贴所需的功能代码。 【参考方案1】:

把这个加进去

-(IBAction)go:(id)sender

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


请查看以下文档: Apple Doc

【讨论】:

以上是关于如何将此 Objective-C 代码放入按钮操作中?的主要内容,如果未能解决你的问题,请参考以下文章

如何将 AppDelegate Swift 代码放入 Objective-C AppDelegate 文件并使其工作?

如何将 QLabel 放入切换按钮 Qt c++

如何在 Objective-C 中使用 buttonWithType 添加按钮样式?

如何将此标志放入 LibreOffice Writer

如何从 Objective-C 代码中删除一次性使用的类变量?

如何在按钮Objective-C的标题上设置字体