gpt4 book ai didi

iphone - 从 NSObject 类调用 presentModalViewController

转载 作者:太空狗 更新时间:2023-10-30 03:49:47 26 4
gpt4 key购买 nike

在我的 NSObject 子类中,我想调用类似的东西

    [[self navController] presentModalViewController:myView animated:YES];

但是我的尝试都没有成功。如果我不在 UIViewController 的子类中,如何调用模态视图?

解决方案:

#import "myProjectNameAppDelegate.h"
// ...
MyViewController *myView = [[MyViewController alloc] init];
myProjectNameAppDelegate *appDelegate = (myProjectNameAppDelegate *)[[UIApplication sharedApplication] delegate];
[[appDelegate navController] presentModalViewController:myView animated:YES];

最佳答案

调用 presentModalViewController 的更好方法是将 viewcontroller 传递给 NSobject 类。从 uiviewcontroller 调用 nsobject 函数这是带有邮件示例的代码

在 View Controller 中//你当前的 View

[nsobjectclassObject OpenMailComposer:self];//这会将viewcontroller带到NSobject

在 NSObject 类中//可能是共享类

-(void)OpenMailComposer:(UIViewController*)view
{

viewControllertoShow = view; // viewControllertoShow is UIVIewcontroller object
MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc]init];
mailView.mailComposeDelegate = self;
[mailView setSubject:@"Hey! check this out!"];
[viewControllertoShow presentModalViewController:mailView animated:YES];
}

要从 NSObject 类 中解雇,您可以执行以下操作

[viewControllertoShow dismissViewControllerAnimated:YES]

关于iphone - 从 NSObject 类调用 presentModalViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3760286/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com