没有已知的选择器实例方法 [英] No known instance method for selector

查看:90
本文介绍了没有已知的选择器实例方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm developing an iOS 4 application using latest SDK, XCode 4.2 and ARC.

我已将方法添加到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

它在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

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

But, when I send a message to that method in ViewController.m

- (IBAction)goSecondClicked:(id)sender
{
    [[[UIApplication sharedApplication] delegate] showSecondViewController];
}

我收到以下编译器错误:

I get the following compiler error:

自动参考计数问题 选择器'showSecondViewController'的未知实例方法

Automatic Reference Counting Issue No known instance method for selector 'showSecondViewController'

有任何线索吗?

推荐答案

您将需要强制转换为以下对象的委托对象:

You will need to cast the delegate object that you get as:

AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];

然后在appDelegate

这篇关于没有已知的选择器实例方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆