我有一个工具栏,我想发布一个textField。我正在尝试使用以下代码,但它不起作用:
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:@"Item" style:UIBarButtonItemStyleBordered target:self action:@selector(action:)];
UITextField *customItem1 = [[UITextField alloc] init];
NSArray *items = [NSArray arrayWithObjects: customItem, customItem1, nil];
[self setToolbarItems:items animated:YES];
答案 0 :(得分:5)
工具栏项必须全部为UIBarButtonItems。为了显示其他内容,您将视图嵌入到项目中:
UIBarButtonItem *customItem1 = [[UIBarButtonItem alloc] initWithCustomView:view];
//view is the embedded view, in your case a UITextField