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

您已经在 HypnosisterAppDelegate 上实现了 canBecomeFirstResponder,它不是 UIResponder 子类。然后您将 becomeFirstResponder 发送到您的自定义视图 (HypnosisView)。

HypnosisView(不是 HypnosisterAppDelegate)需要这样做:

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