I tried this to add UITextField to a UIToolbar but got a run-time error with reason as: [UITextField view]: unrecognized selector sent to instance ...
[toolbar setItems:[NSArray arrayWithObjects:textField, nil]];
toolbar is an instance of UIToolbar and textField is an instance of UITextField.
The items
of a UIToolbar
have to be of type UIBarButtonItem
. Use initWithCustomView:
to create a toolbar item that contains your text field.
UIBarButtonItem *textFieldItem = [[UIBarButtonItem alloc] initWithCustomView:textField];
toolbar.items = @[textFieldItem];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With