【问题标题】:Navigation From UIViewController to Appdelegate从 UIViewController 导航到 Appdelegate
【发布时间】:2012-06-11 05:46:52
【问题描述】:

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

IBAction on button的方法和代码是

-(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 *”类型的参数

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

【问题讨论】:

  • 我认为您无法导航到 AppDelegate 类。它在应用程序启动时首先被调用,通常用于存储全局变量和函数......只需从任何类调用这些方法和变量......
  • 导航到 AppDelegate 是什么意思...?是 [self.navigationController popToRootViewController];你期待的那个?
  • 我也试过..SimpleDemoAppDelegate *obj=[[SimpleDemoAppDelegate alloc]init]; [self.navigationController pushViewController:obj 动画:YES]
  • @anonymous 实际上我正在尝试集成两个不同的演示应用程序。
  • 对于这个要求,你可能应该重新考虑在两种应用模式之间切换的方式。您只能拥有一个 AppDelegate - 因此您需要将两个 appDelegate 合并为一个。您可以考虑将 -setRootViewController (UIWindow) 作为在应用模式之间切换的一种方式

标签: iphone objective-c ios xcode4.2 ios-simulator


【解决方案1】:

我想你忘了写 appDelegate 的 viewcontroller 属性看看这个

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

【讨论】:

    猜你喜欢
    • 2019-09-22
    • 1970-01-01
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-19
    • 1970-01-01
    相关资源
    最近更新 更多