Ios: error de sintaxis al intentar agregar un oyente a la vista de texto

I have a textView for which the submit button gets overlapped by the keyboard, so I am trying to add a listener for when a user taps anywhere else on the screen to get rid of the keyboard.

I am trying to add code like this to my controller:

-(void)touchesBegan:(NSSet *) touches withEvent:(UIEvent *)event
{
    [textView resignFirstResponder];
}

but this gives a syntax error that the textView is not declared. But that is confusing because I added the textView to the screen already.

Aquí está el código:

#import "FeedbackController.h"

@interface FeedbackController ()

@end

@implementation FeedbackController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}



- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void)touchesBegan:(NSSet *) touches withEvent:(UIEvent *)event
{
    [textView resignFirstResponder];
}

- (IBAction)submitFeedback:(id)sender {
    NSLog(@"This is a test hello");
}
@end

And here is how the screen looks like: enter image description here

Any idea how I can try to reference the textView correctly? and how I can make the keyboard disappear when the other parts of the screen are touched?

¡Gracias!

preguntado el 03 de julio de 12 a las 23:07

You need to just fix your user interface so that it doesn't overlap, I'd say. -

2 Respuestas

In your .h file you will need to create an IBOutlet En el correo electrónico “Su Cuenta de Usuario en su Nuevo Sistema XNUMXCX”. textView variable, here is how you create the outlet vista de acceso dentro de un guión gráfico

contestado el 23 de mayo de 17 a las 12:05

Thanks, I was able to crate this line in the header file: @property (weak, nonatomic) IBOutlet UITextView *textArea; - geekedout

textArea is the name I gave it. But how do I reference it now in the .m file? - geekedout

Should it be [self.textArea resignFirstRespnder] - geekedout

You need to make a property for your textView which is an IBOutlet. Then you can connect it in interface builder and call:

[self.textView resignFirstRespnder] 

when you want the keyboard to hide.

Respondido 03 Jul 12, 23:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.