2012-04-28 65 views
0

已经建立了我的appDelegate以返回firstResponder状态,但是当我编译(它编译好)时,控制台返回“无法成为第一响应者”,但没有说明原因。不能返回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; 
} 

回答

3

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

HypnosisView(不是HypnosisterAppDelegate)需要做到这一点:

-(BOOL)canBecomeFirstResponder 
{ 
    return YES; 
} 
+0

谢谢。我将canBecomeFirstResponder移动到HypnosisView,它工作! – pdenlinger 2012-04-28 17:56:00