gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 05:10:27 24 4
gpt4 key购买 nike

我正在使用最新的 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

并在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 中的那个方法发送消息时

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

我收到以下编译器错误:

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

有什么线索吗?

最佳答案

您需要将获得的委托(delegate)对象转换为:

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

然后调用appDelegate上的方法

关于iphone - 选择器没有已知的实例方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8672246/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com