Iphone UIPickerView已添加到uitableviewcontroller.view中';t旋转
我在UITableViewController中有一个UIPickerView作为子视图,我希望在单击某一行时将其向上滑动到位。我已经实现了必要的数据源和委托方法,但是pickerview的行为很奇怪。它的动作就像被机械卡住了一样,它不能正常旋转,它只是移动了一点。如果我尝试旋转它几次,我会在调试器控制台中收到以下消息: SendDelegateMessage:委派失败 等待10秒后返回。 主运行循环模式: UITrackingRunLoopMode,如果您没有 将触摸屏用于整个系统 间隔(可延长此时间) 等等),请提交一个bug 我在谷歌上搜索了一下,结果一无所获。 无论如何,这是相关的代码。正如您可能猜到的,这是一个数字选择器(用于选择百分比值) 如您所见,我使用transform属性将选择器移入和移出(向下)我的主视图;启动编辑和停止编辑方法由teble视图中的选择触发。然而,出于调试目的,我消除了这些转换,并将选择器放在表的顶部,但没有任何更改。我也评论了didSelect方法,但这也没有改变任何事情。 顺便说一下,同一个选择器视图构造代码在同一个应用程序的另一个视图中是正确的。 有什么建议吗?Iphone UIPickerView已添加到uitableviewcontroller.view中';t旋转,iphone,cocoa-touch,Iphone,Cocoa Touch,我在UITableViewController中有一个UIPickerView作为子视图,我希望在单击某一行时将其向上滑动到位。我已经实现了必要的数据源和委托方法,但是pickerview的行为很奇怪。它的动作就像被机械卡住了一样,它不能正常旋转,它只是移动了一点。如果我尝试旋转它几次,我会在调试器控制台中收到以下消息: SendDelegateMessage:委派失败 等待10秒后返回。 主运行循环模式: UITrackingRunLoopMode,如果您没有 将触摸屏用于整个系统 间隔(可延
干杯,您并不是真的使用viewDidLoad中的代码将选择器添加到UITableView。UITableView在UITableViewCells中只能有控件/行,这些控件/行在CellForRowatinex方法中指定。我们不能像对UIView那样向UITableView添加控件 尝试改用UIView的子类,并将UITableView和选择器添加到此UIView子类
如果只想使用UITableViewController子类,请创建自定义单元格并将选择器添加到此自定义单元格。但如果静态添加此单元格,则无法隐藏/取消隐藏此单元格。然后你必须使用重载数据。我建议使用UIView子类。非常感谢,这个问题让我抓狂。事实上,我有点怀疑UITableViewController可能是罪魁祸首,但并没有尽力去改变它。我现在意识到我只是添加了5行代码来测试我的怀疑。干杯,大卫
- (void)viewDidLoad {
[super viewDidLoad];
percentPicker = [[UIPickerViewalloc] initWithFrame:CGRectMake(0,420, 320, 200)];
percentPicker.delegate = self;
percentPicker.dataSource = self;
percentPicker.showsSelectionIndicator = YES;
[self.view addSubview:percentPicker];
}
- (void)viewWillAppear:(BOOL)animated {
// sets the rows to the appropriate value
// etc
}
- (void)startEditingPercentage {
[UIView beginAnimations :nilcontext:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIViewsetAnimationDuration:kPickerAnimationDuration ];
percentPicker.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, -220.0);
[UIViewcommitAnimations];
}
- (void)stopEditingPercentage {
NSLog(@"stopEditingPercentage");
[UIView beginAnimations :nilcontext:NULL];
[UIViewsetAnimationBeginsFromCurrentState:YES];
[UIViewsetAnimationDuration:kPickerAnimationDuration];
percentPicker.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
}
#pragma mark UIPickerView delegate and dataSource methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return4;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return10;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
return44;
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *retval = (UILabel *)view;
if (!retval) {
retval= [[UILabel newLabelWithPrimaryColor :[UIColorblackColor ] selectedColor:[ UIColor blackColor] fontSize:22bold:YEStransparent:YES] autorelease];
}
retval.frame = CGRectMake(0, 0, 44, 44);
retval.textAlignment = UITextAlignmentCenter;
retval.backgroundColor = [UIColor clearColor];
retval.text = [NSStringstringWithFormat:@"%i", row];
if (component > 1 ) {
// rows 2 and 3 are decimal, white on black
retval.backgroundColor = [UIColor blackColor];
retval.textColor = [UIColor whiteColor];
}
return retval;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSString *selectedValue;
selectedValue= [NSString stringWithFormat:@"%i%i.%i%i" ,[percentPickerselectedRowInComponent :0], [ percentPickerselectedRowInComponent: 1], [percentPickerselectedRowInComponent:2], [percentPickerselectedRowInComponent:3]];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSString *trimmedValue = [[formatter numberFromString:selectedValue] stringValue];
percentValue.text = trimmedValue;
[formatter release];
}