从UIViewController导航到Appdelegate

3

我正试图通过点击按钮从UIViewController类(名称为CartViewController)导航到Appdelegate(名称为SimpleDemoAppDelegate)。

按钮的IBAction方法和代码如下:

-(IBAction) Go
{
    AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
    UIViewController* presentingViewController = appDelegate.viewController;
}

我也尝试过。
-(IBAction) Go
{
    SimpleDemoAppDelegate *appdelegate=(SimpleDemoAppDelegate *)[UIApplication sharedApplication].delegate;
    [self.navigationController presentModalViewController:appdelegate animated:YES];
}

还有pushViewController方法,但是它显示警告。

发送“SimpleDemoAppDelegate *”到参数类型为“UIViewController *”的不兼容指针类型

有人能解释一下我为什么会看到这个警告吗?


1
我认为你无法导航到AppDelegate类。它是在应用程序启动时首先调用的,通常用于存储全局变量和函数...只需从任何类中调用这些方法和变量即可。 - rohan-patel
我也尝试过...SimpleDemoAppDelegate *obj=[[SimpleDemoAppDelegate alloc]init]; [self.navigationController pushViewController:obj animated:YES] - Ajit Satarkar
@anonymous 实际上我正在尝试集成两个不同的演示应用程序。 - Ajit Satarkar
@anonymous 我其实是iOS新手,正在尝试集成两个不同的演示应用程序,我已将第二个应用程序的所有文件添加到第一个应用程序中。现在我有一个按钮,点击该按钮后,我的编译器必须跳转到第二个演示应用程序,在那里开始SimpleDemoAppdelegate。 - Ajit Satarkar
1
对于这个需求,你可能应该重新考虑在两种应用模式之间切换的方式。你只能有一个AppDelegate - 所以你需要将两个appDelegate合并成一个。你可以考虑使用-setRootViewController(UIWindow)来切换应用程序模式。 - xingzhi.sg
显示剩余6条评论
1个回答

0

我认为您忘记了在appDelegate中编写viewcontroller属性,请查看此处

SimpleDemoAppDelegate *appdelegate=(SimpleDemoAppDelegate *)[UIApplication sharedApplication].delegate;
[self.navigationController presentModalViewController:appdelegate.viewController animated:YES];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接