3
由于UIToolBar上的UIBarbuttonItem的操作没有被调用,因此我遇到了麻烦。
在以下代码中,虽然点击toolBar
上的doneBtn
,但不会调用操作doneBtnAction:
。
你有什么想法解决它吗?在UIToolBar上的UIBarbuttonItem的操作不叫
- (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'中? – hatfinch
“UIPickerView”,“UIToolbar”,“UITextField”的框架的调试视图层次结构。希望能帮到你 – SeraZheng