我正在開發使用最新SDK的iOS 4應用程序,XCode 4.2和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
- (IBAction)goSecondClicked:(id)sender
{
[[[UIApplication sharedApplication] delegate] showSecondViewController];
}
發送消息給該方法
我收到以下編譯器錯誤:
自動引用計數問題 對於選擇 'showSecondViewController'
任何線索沒有已知的實例方法?
我真的希望那downvoters總是解釋他們的理由...雖然不是最好的解決方案,但我的答案很有效 – 2012-01-07 17:46:38