我遇到了困难,UIToolBar上的UIBarbuttonItem的操作没有被调用。
在以下代码中,虽然toolBar
上的doneBtn
被点击了,但是doneBtnAction:
这个操作没有被调用。
你有什么想法来解决它吗?
- (void)viewDidLoad {
UIPickerView *pickerView = [[UIPickerView alloc] init];
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, -44, 320, 44)];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneBtnAction:)];
UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
toolBar.items = @[flex, doneBtn];
[pickerView addSubview:toolBar];
UITextField *textField = [[UITextField alloc] init];
textField.inputView = pickerView;
}
- (void)doneBtnAction:(UIBarButtonItem *)sender {
NSLog(@"%@", sender);
}
doneBtn
在点击时有动画效果吗?toolBar
在pickerView
中的定位是如何实现的? - hatfinchUIPickerView
、UIToolbar
、UITextField
的框架层级结构。希望能对您有所帮助。 - SeraZheng