问题
My Share Extension doesn't require any user input aside from configuration in a table view so I am trying to hide the keyboard when the view is presented in Safari. I'm able to run my code in the simulator fine but when I test on my device, I'm the Share Extension doesn't launch and Safari hangs.
I've tried a few ways to prevent the keyboard from launching
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.textView.text = @"\n Place Holder Text";
self.textView.editable = NO;
}
As well, I tried it in loadView since that is where SLComposeServiceViewController sets the textView and the textView delegate.
-(void)loadView{
[super viewWillAppear:animated];
self.textView.text = @"\n Place Holder Text";
self.textView.editable = NO;
}
And just for fun
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
return NO;
}
All of these work on the Simulator but not on my device.
What could be happening?
Is there some kind of Notification or Observer that I'm (or Safari is) missing
回答1:
You just need to put your code in "viewDidAppear" function. It works fine for me.
-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.textView setText:@" Place Holder Text"];
[self.textView setEditable: NO];
}
来源:https://stackoverflow.com/questions/33925023/can-not-hide-keyboard-with-slcomposeserviceviewcontroller