iphone - 从 UIViewController 到 Appdelegate 的导航

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

我正在尝试通过单击按钮从 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 *”类型的参数

有人可以向我解释为什么我会看到这个警告吗?

最佳答案

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

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

关于iphone - 从 UIViewController 到 Appdelegate 的导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10927295/

相关文章:

iphone - 如何使用包含彩色图像的按钮自定义 UIToolbar?

ios - UIButton 长按事件

ios - 如何在iOS中以编程方式更改颜色集的颜色

苹果手机 : FBConnect Auto post to user wall

iphone - 更新核心数据实体

在 KTPhotoScrollViewController 和 KTThumbsViewController 之间移动时,使用 KTPhotoBrowser 库的 iPhone 状态栏在应用程序中消失

iphone - 将 Twitter 帐户链接到您的 iOS 应用程序

objective-c - GCD dispatch_async 和 NSURLConnection

ios - 带有大图像的 UITableViewCell 不流畅

ios - 在 iOS swift 中查询使用我的应用程序的用户(解析)