0

Have tried [[self jotNotes] resignFirstResponder]; , have tried [self endEditing:YES];

So I have my NoteViewController, which inherits UIViewController, and tries to implement the delegate like so

@interface NOTEController : UIViewController <UITextViewDelegate>
@end

@implementation NOTEController 
-(id)init {
  self = [super init];
    if (self) {
    //  self.delegate = self; //doesnt let me set this, so i assume i do not do that here
      NOTEControllerView * mainView = [[NOTEControllerView alloc] initWithFrame:[UIScreen mainScreen].bounds];
      self.view = mainView; //just a plain custom uiview subclass its boring and not special
    }
  return self;
}
@end

and then in the mainView, i have a bunch of sub-views that are basically a square with a UITextView inside.

the squares class is like this, and they're the ones im trying to dismiss the keyboard from, heres where i set the delegate, the dismissKB method, and the UITextView code. Currently, it will log my keyboard method when pressing the done button, but the keyboard is still present. Would really appreciate if anyone could help me understand why

@interface NOTESubview : UIView <UITextFieldDelegate>
@property (nonatomic, weak) id<UITextFieldDelegate> delegate;
-(UITextView *)jotNotes;
@end

@implementation NOTESubview
-(id)initWithFrame:(CGRect)arg1 {
  self = [super initWithFrame:arg1];
    if (self) {
        self.delegate = self;
        [self addSubview:[self jotNotes]];
    }
  return self;
}
-(UITextView *)jotNotes {
  UITextView * jotNotes = [[UITextView alloc] initWithFrame:CGRectMake(0, self.frame.size.height/5.7, self.frame.size.width, self.frame.size.height -  self.frame.size.height/5.7)];
  UIToolbar* keyboardTextViewBar = [[UIToolbar alloc] init];
  keyboardTextViewBar.barStyle = UIBarStyleDefault;
  [keyboardTextViewBar sizeToFit];
   UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
   UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                    style:UIBarButtonItemStylePlain target:self
                    action:@selector(dismissKB:)];
  [keyboardTextViewBar setItems:[NSArray arrayWithObjects:flexSpace, doneButton, nil]];
  jotNotes.inputAccessoryView = keyboardTextViewBar;
  jotNotes.delegate = self.delegate;
  return jotNotes;
}
-(void)dismissKB:(UIBarButtonItem *)sender {
  //this will log, so im not sure why it wont resign the board no matter what i try
  NSLog(@"keyboard attempted to dismiss by %@", sender);
  [[self jotNotes] resignFirstResponder];
}
user286152
  • 117
  • 1
  • 2
  • 12

2 Answers2

0

I suspect that when the dismissKB method is called, its actually not the one who is currently the first responder.

However, there's a trick where you can just "dismiss the keyboard" from anywhere in your app. You might wanna give it a try:

[[[[UIApplication sharedApplication] delegate] window] endEditing:YES];
Pochi
  • 13,391
  • 3
  • 64
  • 104
0

Add the following line where you are trying to dismiss the keyboard:

[self endEditing:YES];
yoshiiiiiiii
  • 953
  • 8
  • 20