How to use inputAccessoryViewController in iOS 8

In iOS 8, Apple introduced a new property under the UIResponder called inputAccessoryViewController . However, there was no documentation explaining how to use it.

Also, in iOS 8, by setting the inputAccessoryView property of a subclass of UIViewController and creating a subclass, the first responder seems to cause a view controller to leak.

My question is: how can I use inputAccessoryViewController in a subclass of UIViewController ? Is this a solution to the memory leak problem?

+6
source share
2 answers

If you want to use inputAccessoryViewController, you need to subclass all UITextView or UITextField elements and override the readArrorAccessoryViewController property.

 @interface MyTextView: UITextView @property (nonatomic, retain) UIInputViewController *inputAccessoryViewController; @end 

Note that the view manager you provided must be a UIInputViewController (which will give you access to the input of the delegate and text document) and will create an “inputView” (as self.view) if you call [super loadView], which you can add your subroutines . This UIInputView will be appropriately styled for the keyboard. I have not experimented with trying to download from .xib in this case.

I also found the correct size of the inputView (and avoiding a bunch of error constraints), I added the following code

 - (void)updateViewConstraints { self.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.superview.frame), myAccessoryHeight); [super updateViewConstraints]; } 
0
source

Add this method to your code. This will help you. from iOS 7 you need to return UIView only as an accessory.

 -(UIView *)inputAccessoryView{ UIView *accessoryView = [[UIView alloc] initWithFrame:toolView.frame]; toolView.frame = CGRectMake(0, 0, self.view.frame.size.width, 50); [accessoryView addSubview:toolView]; return accessoryView; } 
-1
source

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


All Articles