没有已知的选择器实例方法

Van*_*nel 4 iphone objective-c ios automatic-ref-counting

我正在使用最新的SDK,XCode 4.2ARC开发iOS 4应用程序.

我添加了一个方法 appDelegate.h

#import <UIKit/UIKit.h>

@class ViewController;
@class SecondViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
    UINavigationController* navController;
    ViewController* viewController;
    SecondViewController* secondViewController;
}

@property (strong, nonatomic) UIWindow *window;

- (void) showSecondViewController;

@end
Run Code Online (Sandbox Code Playgroud)

并且它已经实现了 appDelegate.m

#import "AppDelegate.h"

#import "ViewController.h"
#import "SecondViewController.h"

@implementation AppDelegate

@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    viewController.title = @"First";
    navController = [[UINavigationController alloc] initWithRootViewController:viewController];
    self.window.rootViewController = navController;

    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    ...
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    ...
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    ...
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    ...
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    ...
}

- (void) showSecondViewController
{
    secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    secondViewController.title = @"Second";
    [navController pushViewController:secondViewController animated:YES];
}

@end
Run Code Online (Sandbox Code Playgroud)

但是,当我在ViewController.m中向该方法发送消息时

- (IBAction)goSecondClicked:(id)sender
{
    [[[UIApplication sharedApplication] delegate] showSecondViewController];
}
Run Code Online (Sandbox Code Playgroud)

我得到以下编译器错误:

自动引用计数问题选择器'showSecondViewController'没有已知的实例方法

任何线索?

Het*_*ora 5

您将需要转换您获得的委托对象:

AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
Run Code Online (Sandbox Code Playgroud)

然后调用方法 appDelegate