0

我希望 aUIToolbar在单击某个 时显示UITextField,但是在 中定义的工具栏@interface没有显示。这是我用于初始化并将其附加到文本字段的代码:

toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
toolbar.barStyle = UIBarStyleBlackTranslucent;
toolbar.items = [NSArray arrayWithObjects:[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(isDone:)], nil];
toolbar.hidden = NO;
[toolbar sizeToFit];

angleField.inputAccessoryView = toolbar;

有人可以看到我做错了什么吗?

PS 我在另一个项目中使用过类似的代码,并且它有效。这是代码:

 UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
                       [[UIBarButtonItem alloc]initWithTitle:@"Clear" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad:)],
                       [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                       [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad:)],
                       nil];
[numberToolbar sizeToFit];
changes.inputAccessoryView = numberToolbar;

哪里changesUITextField

4

1 回答 1

0

我不确定是不是这样,但我所做的不是setItems:在工具栏上调用,而是调用setItems:animated:,现在它可以工作了......

感谢所有回复并花时间尝试帮助我的人。快乐编码!

于 2013-01-02T17:58:29.073 回答