【发布时间】:2011-03-08 20:06:48
【问题描述】:
我有一个带有自定义单元格的 UIPickerView。每时每刻,我都想知道哪个单元格位于中心位置(在有色选择指示器后面)。 UIPickerView 委托方法
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
确实提供此信息,但仅在选择器视图停止后提供。我正在寻找的是一种在选择器视图仍在旋转且尚未停止时检索当前“选定”单元格的方法。
作为一种解决方法,我尝试通过 KVO 并注册每个单元格的视图更改:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
.
.
[cell addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew context:nil];
}
我确实收到了对observeValueForKeyPath:ofObject:change:context: 的回调,但是无论我向上还是向下滚动选择器视图,收到的值似乎总是相同的:
2011-03-09 08:00:34.429 Project[35069:207] Frame: x=2.00, y=-13.00
2011-03-09 08:00:34.430 Project[35069:207] Location: x=4.00, y=-26.00
2011-03-09 08:00:34.430 Project[35069:207] Change: {
kind = 1;
new = "NSRect: {{2, -13}, {118, 70}}";
old = "NSRect: {{2, -13}, {118, 70}}";
}
2011-03-09 08:00:34.431 Project[35069:207] Frame: x=2.00, y=-13.00
2011-03-09 08:00:34.431 Project[35069:207] Location: x=4.00, y=-26.00
2011-03-09 08:00:34.432 Project[35069:207] Change: {
kind = 1;
new = "NSRect: {{2, -13}, {118, 70}}";
old = "NSRect: {{2, -13}, {118, 70}}";
(Location coordinates are in window frame)
还有什么我可以尝试获得该价值的想法吗?
【问题讨论】:
标签: iphone objective-c uitableview