我有一个工具栏,我想在其中发布文本字段。我正在尝试以下代码,但无法正常工作:

 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];

最佳答案

工具栏项必须全部是UIBarButtonItems。为了显示其他内容,您将视图嵌入到项目中:

UIBarButtonItem *customItem1 = [[UIBarButtonItem alloc] initWithCustomView:view];
//view is the embedded view, in your case a UITextField

关于ios4 - 如何将textField添加到工具栏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4467611/

10-13 03:56