How to add a textField to a toolbar
I have a toolbar where I want to post a textField. I'm trying with the following code but it doesn't work:
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:@"Item" style开发者_StackOverflow社区:UIBarButtonItemStyleBordered target:self action:@selector(action:)];
UITextField *customItem1 = [[UITextField alloc] init];
NSArray *items = [NSArray arrayWithObjects: customItem, customItem1, nil];
[self setToolbarItems:items animated:YES];
The toolbar items must all be UIBarButtonItems. In order to display something else, you embed a view into the item:
UIBarButtonItem *customItem1 = [[UIBarButtonItem alloc] initWithCustomView:view];
//view is the embedded view, in your case a UITextField
精彩评论