【发布时间】:2013-11-18 16:59:23
【问题描述】:
我正在尝试将工具栏添加到UIPicker。
我已经看到正确的方法是这样:
UIToolbar* toolbarWeight= [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
UIBarButtonItem *barButtonDone1 = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleBordered target:self action:@selector(gotoNextField:)];
[toolbarWeight setItems:[NSArray arrayWithObject:barButtonNext1] animated:YES];
weightPickerView = [[UIPickerView alloc]init];
[weightPickerView addSubview:toolbarWeight];
同时:
-(IBAction)gotoNextField:(id)sender{
NSLog(@"Works");
}
选择器工作正常,但按钮不起作用。 在做了一些研究之后,我尝试了这种方法: (我怀疑问题与 UIBarButtonItem 动作有关)
UIButton* myBtn = [[UIButton alloc]init];
myBtn.frame = CGRectMake(0,0,50,24);
[myBtn addTarget:self action:@selector(gotoNextField:) forControlEvents:UIControlEventTouchUpInside];
[myBtn setTitle:@"Next!" forState:UIControlStateNormal];
[myBtn setBackgroundColor:[UIColor orangeColor]];
UIBarButtonItem *barButtonNext1 = [[UIBarButtonItem alloc] initWithCustomView:myBtn];
[toolbarWeight setItems:[NSArray arrayWithObject:barButtonNext1] animated:YES];
也不行。该按钮出现但没有被选中/响应 touchUpInside。
【问题讨论】:
-
“不起作用”是指您的按钮出现在屏幕上,但是当您点击它时没有任何反应?
-
没错。我将编辑问题。
标签: ios7 uipickerview