I'm developing an iOS 4 application using latest SDK, XCode 4.2 and ARC.
I've added a method to 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
And it's implemented in 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
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:
Automatic Reference Counting Issue No known instance method for selector 'showSecondViewController'
Any clue?
You will need to cast the delegate object that you get as:
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
Then call the method on appDelegate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With