cam*_*ilo 11 iphone xcode objective-c uipickerview
我正在尝试使用UIPicker视图,其行为与iPhone代码示例中通常看到的不同.
我想要做的是允许用户滚动选择器内容,但不自动选择选择器的行(使用选择器委托的"didSelectRow"方法).相反,我希望允许用户触摸选择器的中心行,该行会突出显示,并成为选择.
有没有办法实现这个目标?
提前致谢.
小智 15
向UIPickerView添加手势识别器,触发对象中的目标方法:
myGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pickerTapped:)];
[myPicker addGestureRecognizer:myGR];
// target method
-(void)pickerTapped:(id)sender
{
// your code
}
Run Code Online (Sandbox Code Playgroud)
制作一个新的UIControl
[yourcontrol setBackGroundColor: [UIColor clearColor]];做一个方法
- (IBAction) pickerControlTapped
{
[yourpicker selectRow: rand()% yourpickersize
inComponent: 0
animated: YES];
}
0.3.在1和2之间建立连接
[yourcontrol addTarget: self
action: @selector(pickerControlTapped)
forControlEvents: UIControlEventTouchUpInsied];
UIPickerView 只有 2 个委托。
\n\n\n\n所以,我们只能使用7个方法来通过委托来控制UIPickerView。
\n\n\xe2\x80\x93 pickerView:rowHeightForComponent: \n \xe2\x80\x93 pickerView
:widthForComponent: \n\xe2\x80\x93 pickerView:titleForRow:forComponent: \n\xe2\x80\x93 pickerView:viewForRow:forComponent: reusingView: \n\xe2\x80\x93 pickerView:didSelectRow:inComponent: \n\xe2\x80\x93 numberOfComponentsInPickerView: \n\xe2\x80\x93 pickerView:numberOfRowsInComponent:
就这些。
\n\n在UITableViewDelegate 情况下,UITableView 有更多方法用于管理选择。\n例如,\n \xe2\x80\x93 tableView:willSelectRowAtIndexPath:
\n\xe2\x80\x93 tableView:didSelectRowAtIndexPath:
\n\xe2\x80\x93 tableView:willDeselectRowAtIndexPath:
\n\xe2\x80\x93 tableView:didDeselectRowAtIndexPath:
然而...
\n\n在 UIPickerViewDelegate 情况下,只有 1 种方法来响应行选择。
\n\n\xe2\x80\x93 pickerView:didSelectRow:inComponent:
\n| 归档时间: |
|
| 查看次数: |
14354 次 |
| 最近记录: |