pdenlinger
pdenlinger

Reputation: 3917

Can't return firstResponder status

Have set up my appDelegate to return a firstResponder status, but when I compile (it compiles fine), the console returns "Could not become the first responder" but doesn't tell why.

I have attached the code. Can you tell me what's wrong? Thanks in advance.

HypnosisterAppDelegate.m

#import "HypnosisterAppDelegate.h"
#import "HypnosisView.h"

@implementation HypnosisterAppDelegate

@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

  HypnosisView *view = [[HypnosisView alloc] initWithFrame:[[self window]bounds]];
  [[self window]addSubview:view];

  BOOL success = [view becomeFirstResponder];
  if (success) {
    NSLog(@"HypnosisView became the first responder");
    } else {
    NSLog(@"Could not become the first responder");
  }

  self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

-(BOOL)canBecomeFirstResponder
{
  return YES;
}

Upvotes: 0

Views: 95

Answers (1)

Doug Richardson
Doug Richardson

Reputation: 10811

You've implemented canBecomeFirstResponder on HypnosisterAppDelegate, which is not a UIResponder sub-class. You then send becomeFirstResponder to your custom view (HypnosisView).

HypnosisView (not the HypnosisterAppDelegate) needs to do this:

-(BOOL)canBecomeFirstResponder
{
  return YES;
}

Upvotes: 3

Related Questions