从UIViewController导航到Appdelegate

时间:2012-06-07 07:16:02

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

我试图通过单击Button从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 个答案:

答案 0 :(得分:0)

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

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