0

appDelegateをfirstResponderステータスを返すように設定しましたが、コンパイルすると(正常にコンパイルされます)、コンソールは「ファーストレスポンダーになれませんでした」と返しますが、理由はわかりません。

コードを添付しました。何が悪いのか教えてもらえますか?前もって感謝します。

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;
}
4

1 に答える 1

3

UIResponderサブクラスではないHypnosisterAppDelegateにcanBecomeFirstResponderを実装しました。次に、becomeFirstResponderをカスタムビュー(HypnosisView)に送信します。

HypnosisView(HypnosisterAppDelegateではない)はこれを行う必要があります:

-(BOOL)canBecomeFirstResponder
{
  return YES;
}
于 2012-04-28T17:51:44.830 に答える