How to hide the shortcut bar in iOS9

I had the same issue. And so starts a search of SO. So the above helped me out, but the whole, "if iOS9 thing" might be best framed like this:

if ([self respondsToSelector:@selector(inputAssistantItem)]) {
    // iOS9.
    UITextInputAssistantItem* item = [self inputAssistantItem];
    item.leadingBarButtonGroups = @[];
    item.trailingBarButtonGroups = @[];
}

Happily, I'd created a sub-class of a UITextField, (CHTextField) and was in use everywhere. So it was a very easy fix to whack this in the over-ridden "init" method.

Hope it helps.


In Swift 2.0

if #available(iOS 9.0, *) {
    let item : UITextInputAssistantItem = yourTextView.inputAssistantItem
    item.leadingBarButtonGroups = []
    item.trailingBarButtonGroups = []
} else {
  // Fallback on earlier versions
}

Alternatively, just create an extension for UITextField in Swift 2.0 like this.

extension UITextField
{
    public func hideAssistantBar()
    {
        if #available(iOS 9.0, *) {
           let assistant = self.inputAssistantItem;
            assistant.leadingBarButtonGroups = [];
            assistant.trailingBarButtonGroups = [];
        }
    }
}

Then you can just call hideAssistantBar() on any text field you like.

@IBOutlet weak var myTextField: UITextField?;

override public func viewDidLoad() {
    super.viewDidLoad();

    myTextField?.hideAssistantbar();
}

You can pass your textfield name in place of userNameTextField for which you want to remove shortcut bar.

UITextInputAssistantItem* item = [userNameTextField inputAssistantItem];
item.leadingBarButtonGroups = @[];
item.trailingBarButtonGroups = @[];