Why won't my custom view be the first responder, iOS?

I follow the book, iOS Programming Big Nerd Ranch Guide, and I came to a lesson where I have to create a custom HypnosisView view. Now, I believe that this view changes color in the shaking, but it says that I should make him the first responder.

I used

- (BOOL)canBecomeFirstResponder { return YES; } 

and

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

However, whenever I run my application, he always says that he cannot become the first responder.

Any help would be greatly appreciated.

UPDATE

I forgot to mention that I am receiving this output message.

In application windows, it is expected that the root controller will be installed at the end of the application launch.

+4
source share
1 answer

Good. I understood. I needed to put a delegate method

 - (BOOL)canBecomeFirstResponder { return YES; } 

In the CustomView.m file, and not in the application delegation file. Simple fix.

+3
source

Source: https://habr.com/ru/post/1437384/


All Articles